Capture 'Weekends'/'Holidays' between start and end dates and calculate the duration

chatsaurav19
Tera Contributor

Hi All,

 

Is there a way in which we can capture weekends and/or holidays between any start and end dates and calculate the duration?

 

Example : if an SCTASK is created on ( start date ) '2024-04-02 00:00:00' and is closed on ( end date ) '2024-04-15 00:00:00' then I can capture the four weekends in between or any other holidays in between as well?

 

Thanks and Regards,

Saurabh Chatterjee

 

 

2 REPLIES 2

Mark Manders
Mega Patron

You could (ab)use the SLA definitions for this. Create a schedule of Mo-Fr excluding the holidays and copy the outcome of the breach time to your sctask. You are only asking the question, not explaining the use case or exact requirement, but the SLA engine has this functionality. You could try and rebuild it for some reason, but that depends on your use case.

 


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

Dipen Wadhwana
Giga Guru

Hi @chatsaurav19 ,

 

Please try this script or modify as per desired schedule:

var startDate = new GlideDateTime('2014-10-16 02:00:00');
var endDate = new GlideDateTime('2014-10-18 04:00:00');
var schedule = new GlideSchedule();
 
schedule.load('090eecae0a0a0b260077e1dfa71da828'); // loads "8-5 weekdays excluding holidays" schedule
var duration = schedule.duration(startDate, endDate);
gs.info(duration.getDurationValue()); // gets the elapsed time in schedule

Please mark this response as helpful if your question has been answered correctly.