Arcade now and timestamp not returning as documented

1741
7
05-04-2021 12:28 AM
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
7 Replies
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. 

VanessaSimps
Occasional Contributor III

Thank you for this information. What I am wondering is how do I get the value to return without the "GMT ...." I only want to see the date and the hour/minute in my popup. Any tips on how to get this shorten?

Thanks!

VanessaSimps_0-1646168502271.png

 

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi @VanessaSimps ,

You can use the Text function to format the date the way you want. For an example see: https://community.esri.com/t5/arcgis-online-questions/arcade-date-function-for-expression-in-popup/t... and the documentation can be found here: https://developers.arcgis.com/arcade/function-reference/text_functions/#text 

 

0 Kudos
VanessaSimps
Occasional Contributor III

Thank you @XanderBakker 

I finally figured it out! I had to change the time zone on my service and then was able to use the following

// Name: pTimestamp
// Returns the timestamp value in a user friendly way to show in the pop-up. 

text(timestamp(),'dddd, MMMM D, Y @ h:m:s')

which returns this: Tuesday, March 8, 2022 @ 3:34:5 

FredIausly1
New Contributor

When using TimeStamp() or Now() I'm getting the same results with the posted time be in UTC.  I need to be able to convert that in US Central Standard Time, but not able to find a solution.  How do I get the Now() function to provide CST timestamp?  An assistance on this is greatly appreciated.

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi @FredIausly1 ,

When I test with the TimeStamp() and Now() functions they return different results. The TimeStamp() will return the current date-time in UTC and Now() will return the current date-time in my Local time zone. 

You can use the ToLocal() and ToUTC() functions to switch between the time zones, but there is no function to automatically change to another time zone that is not UTC or Local. Be aware that the ToLocal and ToUTC functions will simply add or extract the number of hours difference between UTC and Local time zone indifferent is you provide a UTC or Local time. 

Also, in ArcGIS Online, date-time is stored in UTC and when you manually create a date it will be assumed to be in UTC. 

You can however use the DateAdd() function and add or subtract the number of hours to obtain the date-time in another time zone, but you should account for Daylight Saving Time depending on the date.

0 Kudos
FredIausly1
New Contributor

Thank you XanderBakker for the input.  When testing the ToLocal function with Timestamp it still returns the time in UTC and not expressing it in US CST.  There is still something that I'm missing to convert the time to CST.

0 Kudos