That makes sense as there are two challenges you are probably running up against:
- The timezone is ambiguous when using
date()
with just the date component and a custom format string (hotfix pushed)
now()
is the complete current date and time
1. Timezone Ambiguity
I pushed a hotfix that should improve this for your time format, but here’s the reasoning if you’re interested…
Timezone Ambiguity Details
When you are parsing using date()
with just the date component in the input string and a custom format string, the timezone is ambiguous.
dt = date("2024-08-05")
formatDate(dt) #//2024-08-05T00:00:00-05:00
dt = date("05-08-2024", "DD-MM-YYYY")
formatDate(dt) #//2024-08-04T19:00:00-05:00
-
Note that in the first case, we used standard ISO formatting and the parser assumed it was parsing the raw date in my timezone
-
Whereas in the second it thought it should parse it in UTC and then offset to my timezone.
Hotfix Deployed: Improved Timezone Disambiguation
I pushed out a hotfix which should better disambiguate the timezone using the date format you supplied, so this should work better now.
In other cases, you could explicitly set the timezone to UTC at the top of the expression to force all parsing in UTC, but that could complicate things by making now()
report in UTC, so you would need to adapt for that.
2. Comparing to now()
which has time
The now()
function includes both the date and the time that it currently is. So if you want to compare just dates to dates, you would need to ensure the times are standardized (eg. reset to 00:00
)
Reset ‘time’ component of now()
If you were purely looking for the date comparison excluding the time, you could use the startOfDate()
command to ensure you were comparing the same time across both dates.
Raw now()
includes the time:
dt = now()
formatDate(dt) #// 2024-08-05T11:37:12-05:00
Use startOfDate() to reset time:
dt = now()
dt = startOfDate(dt)
formatDate(dt) #// 2024-08-05T00:00:00-05:00
Full Example - Date Only Comparison
parsedDate = date("31-08-2024", "DD-MM-YYYY") #//2024-08-31T00:00:00+00:00
today = startOfDate(now())
duration = parsedDate - today
formattedDuration = durationAs(duration, "days")