Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 DATEDIFF calculation that excludes Sundays

Author  Topic 

khauskins
Starting Member

2 Posts

Posted - 2012-11-15 : 12:18:13
Hello,

I need to get the difference in days between two dates without counting Sundays. Can this be done with DATEDIFF or is there another way to do it?

Any help would be greatly appreciated! Thanks!

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-11-15 : 12:27:18
You can do this:
DATEDIFF(dd,startDate,EndDate) - DATEDIFF(wk,startDate,endDate);
It should work correctly regardless of your datefirst setting, but check the boundary conditions (when start date or enddate is on a weekend) to see if it is off by 1 and make adjustments as necessary.
Go to Top of Page

khauskins
Starting Member

2 Posts

Posted - 2012-11-16 : 11:56:06
Looks like that worked - thank you!
Go to Top of Page
   

- Advertisement -