Calculate number days between two dates in flow designer

praveen_rajan
Tera Contributor

Hi, Calculate number days between two dates in flow designer. Check condition for start date and end date in catalog variable. If it is more than 30 days, need to calculate the number of days and also create catalog task with short description like "System Administrator has taken leave for 33 days", and assignment group is populated with Help desk.

2 ACCEPTED SOLUTIONS

Amit Gujarathi
Giga Sage
Giga Sage

HI @praveen_rajan ,
I trust you are doing great.

  1. Start by setting up a Flow Designer flow.

  2. Add two catalog variables, "Start Date" and "End Date", to capture the date inputs from the users.

  3. Use a condition element to check if the difference between the start and end dates is more than 30 days.

    • You can use JavaScript code to calculate the number of days between two dates. Here's an example:

var startDate = new Date(input.StartDate);
var endDate = new Date(input.EndDate);
var timeDiff = endDate.getTime() - startDate.getTime();
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



View solution in original post

@praveen_rajan 

something like this

var dt = new GlideDateTime('<startDate>');
var end = new GlideDateTime('<endDate>');
var dur = GlideDateTime.subtract(dt,end);

var days = dur.getDayPart();

if(days > 30){
return 'System Administrator has taken leave for 33 days';
}
Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

@praveen_rajan 

you can use f(x) inline script while creating catalog task and use that script to set short description

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

Can you share the script please?

@praveen_rajan 

something like this

var dt = new GlideDateTime('<startDate>');
var end = new GlideDateTime('<endDate>');
var dur = GlideDateTime.subtract(dt,end);

var days = dur.getDayPart();

if(days > 30){
return 'System Administrator has taken leave for 33 days';
}
Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Amit Gujarathi
Giga Sage
Giga Sage

HI @praveen_rajan ,
I trust you are doing great.

  1. Start by setting up a Flow Designer flow.

  2. Add two catalog variables, "Start Date" and "End Date", to capture the date inputs from the users.

  3. Use a condition element to check if the difference between the start and end dates is more than 30 days.

    • You can use JavaScript code to calculate the number of days between two dates. Here's an example:

var startDate = new Date(input.StartDate);
var endDate = new Date(input.EndDate);
var timeDiff = endDate.getTime() - startDate.getTime();
var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi