How to Compare Date/Time Field with Current Time in Flow Designer?

BibekP
Tera Contributor

Hello Team,

 

How can I check if a Date/Time field is equal to the current date&time in Flow Designer?

 

I’m working with Workflow Studio (Flows) and need to compare a Date/Time field with the current date&time. I want to execute actions based on whether the field matches the current time.

How can I access this field correctly in a Flow Designer script, or is there a better way to implement this functionality?

 

Any help or examples would be greatly appreciated!

Thanks

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@BibekP 

so basically you want to wait till that date/time field value has reached?

If the date/time is reached then you want to proceed?

If yes then you can refer this link and enhance

Flow Designer : Making the flow wait until a specific date time based on a catalog variable 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

3 REPLIES 3

pratikjagtap
Giga Guru

Hi @BibekP ,

 

Solution 1: Use Relative Date Logic in Flow (if precision is not critical)
If you're okay with some flexibility (e.g., checking if it's "Today"), you can use:

  • If current record.date_field on Today
  • If current record.date_field before/after Now

Solution 2: Use a Script Step to Compare Time Within a Range
Use this when you want to check if the field is within a few seconds/minutes of now.

 

(function execute(inputs, outputs) {
var fieldTime = new GlideDateTime(inputs.yourDateTimeField);
var now = new GlideDateTime();

var diffSeconds = Math.abs(now.getNumericValue() - fieldTime.getNumericValue()) / 1000;

// Allow a tolerance of 60 seconds
outputs.match = diffSeconds < 60;
})(inputs, outputs);

 

Input : yourDateTimeField: Date/Time from the current record

Output: match: Boolean (true/false)

 

If my response helped, please hit the 👍Thumb Icon and accept the solution so that it benefits future readers.

 

Regards,
Pratik

Mark Manders
Mega Patron

What are you exactly doing? Since date/time is stored in milli seconds, doing a comparison will almost always return false. You could do a check if it is before or after, or add 'wait' action/condition to your flow, but a solution would depend on you exact use case.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Ankur Bawiskar
Tera Patron
Tera Patron

@BibekP 

so basically you want to wait till that date/time field value has reached?

If the date/time is reached then you want to proceed?

If yes then you can refer this link and enhance

Flow Designer : Making the flow wait until a specific date time based on a catalog variable 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader