Ayesha Fathima

Ayesha Fathima

  • NA
  • 184
  • 30.1k

Get working days,hours,minutes between two dates in sql serv

May 18 2020 6:00 AM

Input
startdate - 2020-05-01 10:05:07.000
enddate - 2020-05-18 12:08:07.000

Expected Output
12D:02H:03M

I need output like aobve which is having hours minutes with days

Iam having query from which iam getting only working days ,below is the query
  1. SELECT (DATEDIFF(dd, receive_date, GETDATE()) + 1)  
  2.   -(DATEDIFF(wk, receive_date, GETDATE()) * 2)  
  3.   -(CASE WHEN DATENAME(dw, receive_date) = 'Sunday' THEN 1 ELSE 0 END)  
  4.   -(CASE WHEN DATENAME(dw, GETDATE()) = 'Saturday' THEN 1 ELSE 0 ENDfrom email   
other query i have like this
  1. select dbo.fn_WorkDays(receive_date, getdate() ) from email

Answers (2)