Arcade now and timestamp not returning as documented

92
1
a week ago
Labels (1)
Morin
by
New Contributor II

How do I know if a date is locale or UTC, it does not make sense?

Why is there a timesone aware "mark" (+2:00) on what is returned from now()?
Using arcade this is what is being returned.

now() - 2021-05-04T09:02:03+02:00

Timestamp() - 2021-05-04T09:02:03+02:00

I would expect now to just return the locale datetime and nothing else?

 

I don't recognize any of this from the documentation:

https://developers.arcgis.com/arcade/function-reference/date_functions/#now

Returns the current date and time

e.g. Mon Oct 24 2016 12:09:34 GMT-0700 (PDT)

 

From documentation https://developers.arcgis.com/arcade/function-reference/date_functions/#timestamp

Returns the current date and time in UTC time

e.g. 29 Mar 2017 08:37:33 pm

 

0 Kudos
1 Reply
XanderBakker
Esri Esteemed Contributor

Hi @Morin ,

What you are seeing is when you write the Now() or Timestamp() to the console, right? If you return the date value you will probably see a date and no indication for the time zone.

When you create a date it will be created in the local time (in your time zone). The +2:00 you are seeing indicates the time zone, which in my case is -5:00 (Colombia). When you create the current time with Now() it will give you the local date time and with Timestamp() it will give you the current UTC date time.

Have a look at a couple of examples below:

Now(): 2021-05-05T09:39:28-05:00
ToUTC(Now()): 2021-05-05T14:39:28-05:00
ToLocal(Now()): 2021-05-05T04:39:28-05:00
ToLocal(ToUTC(Now())): 2021-05-05T09:39:28-05:00

The first, second and fourth lines are correct. The 3rd line does not make sense. I am using ToLocal to convert a UTC date time to my local time zone, but I provide a local time.

Same goes for Timestamp; the first, third and fourth are correct. The second does not make sense since I use a UTC date time and use ToUTC to convert it to UTC. The function assumes that the date time is provided in local time, but it is not the case.

Timestamp(): 2021-05-05T14:39:28-05:00
ToUTC(Timestamp()): 2021-05-05T19:39:28-05:00
ToLocal(Timestamp()): 2021-05-05T09:39:28-05:00
ToUTC(ToLocal(Timestamp())): 2021-05-05T14:39:28-05:00

When working with date time, it is important to know in what time zone there are expressed to be able to handle them correctly.

I do agree that this can be very confusing and prone to errors.