get year from epoch time with decimal-date-time()

569
4
08-03-2023 10:27 AM
mikAMD
by
Occasional Contributor III

I'm trying to check if the year from a field in a layer corresponds to this year.

I'm able to do it with format-date() but I need to do it with decimal-date-time() because I want the form to work on the web app.

today_ddt = field that contains today's year in decimal date time

field_year = field that contains an inspection date (that I ultimately with to compare to today_ddt)

typenamelabelcalculation

bind::type

RESULT survey123 connect

RESULT web app

texttoday_ddttoday_ddtdecimal-date-time(today())int5353
textfield_yearfield_yearint(decimal-date-time(int(pulldata("@layer", "getValue", "attributes.inspection_date", "https://service_url/FeatureServer/14?orderbyfields=inspection_date desc", concat("field1 =", ${field1})))) div 365.25)int531690905600000

 

I get that 53 + 1970 = 2023 and I don't mind wether I get a 53 or 2023, but it has to be the same format for both. I want to compare them but I can't seem to do it because web app always gives a different result than connect.

I tried all the possibilities changing "type" to integer, text or date; "bind::type" to int or nothing, adding/removing int(); dividing by 365.25 or not..

Help?

 

0 Kudos
4 Replies
DougBrowning
MVP Esteemed Contributor

Have you tested

format-date(${previous_time}, '%Y') = format-date(now(), '%Y') 

0 Kudos
mikAMD
by
Occasional Contributor III

Yeah. In Survey123 Connect it works, where both fields show the value "2023" and I get "true". But in the web app, both fields show the value "1690905600000" and I get "false". 😞

0 Kudos
mikAMD
by
Occasional Contributor III

I got it.

From Decimal date time: "For these types of calculations, perform a calculation on a decimal date format value, perform the calculation, and convert the result to a date value."

Today's year: format-date(date(decimal-date-time(now())), '%Y')

Get year from date in layer: format-date(date(decimal-date-time(int(pulldata("@layer", "getValue", "attributes.inspection_date", "https://service_url/FeatureServer/14?orderbyfields=inspection_date desc", concat("field1 =", ${field1}))))), '%Y')

EDIT:

I think in all my tests I mixed up some fields and thought I had it, but nope still same problem. Back to the drawing board. 

 

mikAMD
by
Occasional Contributor III

@IsmaelChivite, any idea how to get this working? Check if the date in a layer corresponds to this year?

No matter what I do, can't seem to get the year from when doing date(decimal-date-time(int(pulldata("@layer"))) and other variations.

Works perfectly in Connect, but I've been racking my brain for the web app.

0 Kudos