Queries the number of weeks of the current month for a given date.
Source: Internet
Author: User
SQL query statement declare @ datedatetime; set @ dategetdate () -- train of thought, the given date is the week of the current year-the first day of the month where the given date is located is the week of the current year selectdatepart (week, @ date)-datepart (week, dateadd (month, datediff (month, 0, @ date), 0) + 1 [w: query the SQL query statement for the week of the current month for the given date
Declare @ date datetime;
Set @ date = getdate ()
-- Train of thought: the given date is the week of the current year-the first day of the given date is the week of the current year
Select datepart (week, @ date)-datepart (week, dateadd (month, datediff (month, 0, @ date), 0) + 1 [weekofmonth]
Select datepart (week, @ date)-datepart (week, dateadd (day, 1-datepart (day, @ date), @ date) + 1 [weekofmonth]
Go
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.