How to use expression to see if current date/time > 4:00 pm


Is there an easy way in EM to compare today() time to see if it’s > 4pm?

You need now(), not today().

Now() returns a number with a fractional part. The integer part is the current date (the number of days since 1900 Jan 1st), and the fractional part is the current time. 1 day = 24 hours. Therefore 1 hour = 1/24.

4pm is 16/24 = 0.6666666666666667

Therefore, to check if the current time > 4pm you can use the following expression:

let time = now()
(time - floor(time)) > 16/24

See also: Date Addtion or Time Addtion Function available?

Thank you for your quick response. We have a report that runs at 7:00 am Mon - Fri but also runs at 4:00 pm on Tues. We some times have an issue when the afternoon run at 4:00 kicks off. If the current file from the morning run is open, the report will not be created because it’s being accessed by someone and then errors out. So what I was wanting to do was to put an ‘am’ in the file name for the morning run, and a ‘pm’ in the file name for the afternoon run. This only happens once a week but I was able to use your example for the file name logic as so:

IF (NOW() - FLOOR(NOW())) < 12/24 THEN "C:\EM\FileName - " & format(today(),‘yyyyMMdd’) & ’ am’ & “.xlsx”
ELSE "C:\EM\FileName - " & format(today(),‘yyyyMMdd’) & ’ pm’ & “.xlsx”

This is working like a champ. Thank you again for your response.

You’re welcome )