Skip to main content
October 1, 2021
Solved

Facing issue with date comparison

  • October 1, 2021
  • 3 replies
  • 0 views

Hi,

I am trying to compare two dates one is stored in DB (lets call it dbValue) and another one is from now ( ).

Now, where I have :

dbValue: 10/02/2021 09:00 AM

now: 10/1/2021 9:18 AM EDT

dbValue<now

it gives me true

dbValue: 09/30/2021 09:00 AM

now: 10/1/2021 9:18 AM EDT

dbValue<now

it again gives me true

Not sure what's the issue, please help me.

    Best answer by hrishikeshd997

    Is your dbValue a local variable or a rule input of date and time type? If its a rule input of the same data type as now() there shouldn't be an issue if not then it is comparing a text with a timestamp which will not give desired output. Try converting it using todatetime before comparison and it should work.

    todatetime("10/02/2021 09:00 AM") < now()

    3 replies

    October 1, 2021

    Is your dbValue a local variable or a rule input of date and time type? If its a rule input of the same data type as now() there shouldn't be an issue if not then it is comparing a text with a timestamp which will not give desired output. Try converting it using todatetime before comparison and it should work.

    todatetime("10/02/2021 09:00 AM") < now()

    October 1, 2021

    Thanks it worked, I had dbValue stored in text format.

    csteward
    October 1, 2021

    Also to note, the todatetime() function applies a timezone offset, "todatetime("10/02/2021 09:00 AM")" in eastern time will return 5 AM ET.  To return the actual text value of the time, apply gmt() as:

    gmt(todatetime("10/02/2021 09:00 AM"))

    It is also strongly encouraged to use proper data types when storing to the DB, storing such things as datetime values as text will most certainly present issues down the road.