Skip to main content
December 15, 2022
Question

How to compare Time

  • December 15, 2022
  • 6 replies
  • 0 views

Hi All,

I have to check whether the current time(irrespective of any user time zone) is between 7pm EST to 9am EST.

So we tried to convert the current time to EST first and then to compare it with "7:00 PM" & "9:00 AM" EST (by creating text constant).

We just tested with below code to check whether comparison works fine by changing the constant value, but it fails 

totime(

gmt(

 local(now(), "EST" )
    )
  ) > totime(cons!xyz) 

where cons!xyz = "7:00 PM" (a text constant)

So please help me how to make this work. Thanks in advance.

    6 replies

    stefanhelzle0001
    December 15, 2022

    Why do you convert the time back and forth? Appian internally works with UTC only and converts any timestamp from/to the users timezone automatically. Storing a time as a text is also a difficult decision.

    and(
      hour(now()) >= 7,
      hour(now()) <= 21
    )

    December 15, 2022

    Hi Stefan, thanks for your response. I got your point and tried testing with the above code, but it is not giving me the expected result. Please correct me if I am wrong.

    My appian time zone is IST, and current time is 9:42 PM, but hour(now()) gives me output as 16 instead of 21,please refer the below screenshot,

    stefanhelzle0001
    December 15, 2022

    That is expected. Be aware that calling now() in the expression editor evaluates it in UTC by default. When called normally it uses the users timezone as configured in the user settings.

    Appian is pretty good in making time just work.