Solved

How to exclude weekends when using Diffdate function

Posted on 2011-09-17
3
297 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
Comment Utility
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
Comment Utility
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
Comment Utility
Just what I wanted. Thanks.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
'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 …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

772 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

14 Experts available now in Live!

Get 1:1 Help Now