Calculate duration between two dates by excluding weekends in sqlserver
I have table with name "fact_inc" with columns ticketId,status,opendate,closedate. My requirement is to calculate weekday duration. 1. When status is inprogress then find difference between opendate minus getdate with out weekends. Condition: incase if ticketid opened on Saturday or sunday then opendate should be consider as monday, then need duration between monday and getdate. Ex: ticket id1 having opendate 2023-06-16 00:00:00(yyyy-mm-dd hhmmss), status is inprogress , result duration should be 4 days excluding weekends ,here im considering getdate as 2023-06-22 00:00:00. Ex2 ticket id2 having opendate 2023-06-17 00:00:00(yyyy-mm-dd hhmmss), status is inprogress , then we need to calculate duration between monday( 2023-06-19 00:00:00) and today( 2023-06-22 00:00:00), result duration should be 3 days excluding weekends ,here im considering getdate as 2023-06-22 00:00:00.