How to Compare Date/Time Field with Current Time in Flow Designer?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-11-2025 08:15 PM - edited 05-11-2025 08:15 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-13-2025 05:20 AM - edited 05-13-2025 05:21 AM
I have an action that does this. You could modify it to function differently to meet your scenario, but here is how mine works.
This is the Input step:
Here is the script step:
Here is the script:
(function execute(inputs, outputs) {
try {
var startingPoint = new GlideDateTime(inputs.start_date);
var endingPoint = new GlideDateTime();
if (inputs.end_date)
endingPoint.setValue(inputs.end_date);
if (startingPoint.before(endingPoint))
{
var startValue = startingPoint.getNumericValue();
var endValue = endingPoint.getNumericValue();
var difference = endValue - startValue; // difference in milliseconds
outputs.difference_minutes = parseInt(difference/(1000*60));
outputs.difference_hours = parseInt(difference/(1000*60*60));
outputs.difference_days = parseInt(difference/(1000*60*60*24));
var weekCounter = 0;
var temporaryDateWeek = new GlideDateTime(startingPoint);
while(temporaryDateWeek.before(endingPoint))
{
temporaryDateWeek.addDaysUTC(7);
if (temporaryDateWeek.before(endingPoint))
weekCounter++;
}
outputs.difference_weeks = weekCounter;
var monthCounter = 0;
var temporaryDateMonth = new GlideDateTime(startingPoint);
while (temporaryDateMonth.before(endingPoint))
{
temporaryDateMonth.addMonthsUTC(1);
if (temporaryDateMonth.before(endingPoint))
monthCounter++;
}
outputs.difference_months = monthCounter;
var yearCounter = 0;
var temporaryDateYear = new GlideDateTime(startingPoint);
while (temporaryDateYear.before(endingPoint))
{
temporaryDateYear.addYearsUTC(1);
if (temporaryDateYear.before(endingPoint))
yearCounter++;
}
outputs.difference_years = yearCounter;
}
else
{
var startValue = startingPoint.getNumericValue();
var endValue = endingPoint.getNumericValue();
var difference = startValue - endValue; // difference in milliseconds
outputs.difference_minutes = parseInt(difference/(1000*60));
outputs.difference_hours = parseInt(difference/(1000*60*60));
outputs.difference_days = parseInt(difference/(1000*60*60*24));
var weekCounter = 0;
var temporaryDateWeek = new GlideDateTime(startingPoint);
while(temporaryDateWeek.after(endingPoint))
{
temporaryDateWeek.addDaysUTC(-7);
if (temporaryDateWeek.after(endingPoint))
weekCounter++;
}
outputs.difference_weeks = weekCounter;
var monthCounter = 0;
var temporaryDateMonth = new GlideDateTime(startingPoint);
while (temporaryDateMonth.after(endingPoint))
{
temporaryDateMonth.addMonthsUTC(-1);
if (temporaryDateMonth.after(endingPoint))
monthCounter++;
}
outputs.difference_months = monthCounter;
var yearCounter = 0;
var temporaryDateYear = new GlideDateTime(startingPoint);
while (temporaryDateYear.after(endingPoint))
{
temporaryDateYear.addYearsUTC(-1);
if (temporaryDateYear.after(endingPoint))
yearCounter++;
}
outputs.difference_years = yearCounter;
}
}
catch (err)
{
gs.addErrorMessage('Error occurred in date comparison: ' + err.message);
}
})(inputs, outputs);
And here is the output step: