Forum Discussion
Thanks a lot everyone. All your replies have contributed to me crafting the right expression.
In the end I wanted to compare against midnight of today so I can filter and only process items that are created between now and midnight (last night) in the current timezone. Note that $orderDate is stored properly in UTC format.
The expression ends up being this (I know, not very elegant…):
Date.parse($orderDate) >= Date.parse(Date.now().toLocaleDateString()+“T00:00:00.000-0” + ((Date.now().toLocaleDateTimeString({timeZone:“US/Eastern”, format: “HH”}) - Date.now().toLocaleDateTimeString({timeZone:“UTC”, format: “HH”})) * -1) + “:00”)
This following expression would give me the proper date/time I needed (which is today at midnight in the -05/US-Eastern timezone) to compare my $orderDate against.
Date.parse(Date.now().toLocaleDateString()+“T00:00:00.000-0” + ((Date.now().toLocaleDateTimeString({timeZone:“US/Eastern”, format: “HH”}) - Date.now().toLocaleDateTimeString({timeZone:“UTC”, format: “HH”})) * -1) + “:00”)
Value at the time of this writting:
2022-01-12T05:00:00.000 UTC
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