I need to calculate week number of the month using MS SQL sample input and output given below
01/04/2016(Friday) 1 (1st week),
04/04/2016(Monday) 2 (2nd week),
11/04/2016(Monday) 3 (3rd week)
I need output like this Consider Sunday as week starting date and Saturday as week ending date I think this examples are clear
Thanks
I am not sure how to get the output you are looking for -- I'm simply not sure what it means. However, you can set the first day of the week using DATEFIRST
. This applies to most of the functions, such as DATEPART
.
The documentation is here .
for MySQL
select (dayofmonth(current_date)-weekday(current_date))/7+1
PostgreSQL
select (extract(day from current_date)-extract(dow from current_date))/7 +1;
just put your date in the current_date
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.