Sunday, February 19, 2012

DATEDIFF Return Monday - Friday or Just weekdays

I have a query and am trying to just return the difference between two dates but not include weekends.

For instance, if I have 08/21/2006 - 08/28/2006, there are 6 weekdays.

I tried this, but I am getting 7 as a result.

SELECTDATEDIFF(weekday, request_start_date, request_end_date)AS days_off, request_idFROM request
Any help would be greatly appreciated.

You may find this UDF helpful

http://www.sqlservercentral.com/columnists/sjones/businessdays.asp

|||

You need DateDiff with the correct DatePart so I think you need either DayofYear or Hours so you can convert it back to days. Try the link below for details. Hope this helps.

http://msdn2.microsoft.com/en-us/library/ms189794.aspx

No comments:

Post a Comment