cancel
Showing results for 
Search instead for 
Did you mean: 

Compare DateTime against a point in time (in local time zone)

Kien
New Contributor

Hi, I’m having a hard time trying to figure out a way to compare a DateTime property (which is stored in UTC) to a point in time i.e. Today midnight (in the current local time zone which is US/Eastern -05:00)…

The closest thing came to find is Date.parse(Date.now().toLocaleDateString()+"T00:00:00.000-05:00") which in turns gives me “2022-01-12T05:00:00.000 UTC”… but I don’t want to hard code the “-05:00” portion as during DST it would be -04:00…

Any ideas? Thanks!

5 REPLIES 5

del
Contributor III

@Kien,

I know you have a working expression, but here’s another that may also work for you. I can’t say it’s preferred, but it does shorten the code a bit.

Date.parse(Date.now().toLocaleDateString()).plusHours((Date.now() - (Date.parse(Date.now().toLocaleDateTimeString({"timeZone":"US/Eastern"})))) / 3600000)

I’m glad you brought this question to the community. I’ve had similar challenges in the past and I think having worked through this again today may help me clean up some very old code.

[Followup Edit]
This expression also handles both UTC- and UTC+ offsets