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)
type | name | label | calculation | bind::type | RESULT survey123 connect | RESULT web app |
text | today_ddt | today_ddt | decimal-date-time(today()) | int | 53 | 53 |
text | field_year | field_year | int(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) | int | 53 | 1690905600000 |
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?
Have you tested
format-date(${previous_time}, '%Y') = format-date(now(), '%Y')
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". 😞
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.
@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.