Determine the number of rest periods in a time period
Source: Internet
Author: User
Declare @ B datetime, @ E datetime
Set @ B = '2017-12-20'
Set @ E = '2017-01-21'
Select datediff (Week, @ B, @ E)
, Datediff (Week, @ B, @ E) + case when datepart (weekday, @ B)> 1 then 0 else 1 End-case when datepart (weekday, @ E)> = 1 then 0 else 1 end as Sunday count
, Datediff (Week, @ B, @ E) + case when datepart (weekday, @ B)> 2 then 0 else 1 End-case when datepart (weekday, @ E)> = 2 then 0 else 1 end as Monday count
, Datediff (Week, @ B, @ E) + case when datepart (weekday, @ B)> 3 then 0 else 1 End-case when datepart (weekday, @ E)> = 3 then 0 else 1 end as Tuesday count
, Datediff (Week, @ B, @ E) + case when datepart (weekday, @ B)> 4 then 0 else 1 End-case when datepart (weekday, @ E)> = 4 then 0 else 1 end as Wednesday count
, Datediff (Week, @ B, @ E) + case when datepart (weekday, @ B)> 5 then 0 else 1 End-case when datepart (weekday, @ E)> = 5 then 0 else 1 end as number of Thursday
, Datediff (Week, @ B, @ E) + case when datepart (weekday, @ B)> 6 then 0 else 1 End-case when datepart (weekday, @ E)> = 6 then 0 else 1 end as Friday count
, Datediff (Week, @ B, @ E) + case when datepart (weekday, @ B)> 7 then 0 else 1 End-case when datepart (weekday, @ E)> = 7 then 0 else 1 end as Saturday count
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.