How to get difference between two date/time stamp in number of days and excluding saturday sundays ?

Gaurav Kumar15
Giga Guru

Hi All,

Could anyone please help me in finding difference between 2 timestamps in no. of days, and that too excluding saturdays and sundays.

Any leads would be highly appreciated.

Thanks,

Gaurav Kumar

3 REPLIES 3

shaveta
Mega Expert

Hi Gaurav..did you find a way to get the difference as number of days. I also have a similar requirement.


Gurpreet07
Mega Sage

Use following function to get number of days excluding weekends.



function getDateDifferenceExcWeekends(start , end){


//Make Sure that start and end are GlideDateTime Objects  


  var days = 0 ;


  while (start < end) {


  start.addDays(1);


  if (start.getDayOfWeek() != 6 && start.getDayOfWeek() != 7)           //excluding Weekends


  {


  days++ ;


  }


  }


  return days;


}


Hi Gurpreet,



I have following requirement


Set 'resolved' incident that have not been updated in the past five days to 'closed' status.



While updating records I want exclude Saturday and Sunday.