Solved

How to exclude weekends when using Diffdate function

Posted on 2011-09-17
3
299 Views
Last Modified: 2012-06-27
I have a query to measure delivery performance. Using
DATEDIFF ( DAY , SIH.[Order Date], SIL.[Shipment Date] ) AS [Ship Days],
this gives me a value including weekends.
How do I exclude the weekends?
Thanks.
0
Comment
Question by:kcoxon
  • 2
3 Comments
 
LVL 15

Expert Comment

by:Haris Djulic
ID: 36553879
try this
where datepart (dw,  SIL.[Shipment Date]) is not in ('saturday', 'Sunday')

Open in new window

0
 
LVL 15

Accepted Solution

by:
Haris Djulic earned 250 total points
ID: 36553893
that was fast reading.. ;)

here is the wanted solutions just replace @startdate, @enddate


select datediff(dd,@startdate,@enddate)-2*datediff(ww,@startdate,@enddate)
+ case when datepart(dw,@startdate)=1 or datepart(dw,@enddate)=7 then -1
when datepart(dw,@startdate)=7 or datepart(dw,@enddate)=1 then +1
else 0 end
0
 

Author Closing Comment

by:kcoxon
ID: 36554133
Just what I wanted. Thanks.
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now