How to determine if today is between 2 dates

A task I frequently need to do is determine if today is between 2 dates (without time). I’m wondering if anyone has found a more elegant way to do this? I’ve been converting the start and end dates from an oracle database, and the current date to strings, then comparing them. It’s ugly and I feel like there should be a better way?
Date.now().toLocaleDateString() >= $GZCNTRL_START_DATE.toString().substr(0,10) && Date.now().toLocaleDateString() <= $GZCNTRL_END_DATE.toString().substr(0,10)

Have you seen this documentation on Comparing Two Dates

Yes, but I didn’t see how I could use it. Now() returns date and time, and I need just date (so the last day in the range isn’t omitted), plus I had issues because the dates from Oracle are local date and that gives an error comparing to the Now() date --which must be UTC?

Hi Wendy,

When invoking date parse and format was not set, it will convert that into UTC, after parsing the 2 dates all of your dates are now set in UTC, removing time or setting it up as 00:00:00 you can invoke the .toLocaleDateString()… then do the date parse again to perform compare dates… see screenshot below

I think that is pretty much exactly what I’m currently doing–converting the dates to strings and then comparing. Note, you can’t use LocaleDateString on an Oracle date datatype (it fails), you have to use toString. I think it is cludgy because what it the point of having date datatypes if you have to convert them to strings to compare them?..which makes me wonder if maybe there is something I am failing to understand about how to work with dates in Snaplogic.

1 Like