I would like to have the week number and year for a specific date from MySQL with the following rules:
- If the date is at the end of the year, but in the first week of the next year, I need to return 1 as the week number.
- If the date is at the beginning of the year, but in the last week of the previous year, I need to return 52 (or 53) as the week number.
I read the week function in MySQL, but I cannot get the result that I want.
Date and time functions: WEEK(date[,mode])
I am on the French calendar, so I have to start the week on Monday, and week 1 is the first week with more than 3 days this year.
Therefore, I can only use options 1 and 3.
When I write the following queries:
select week ('2012-12-31', 3), result 1
select week ('2012-12-31', 1), result 53
When I test January 1, 2016:
('2016-1-1', 3), 53
('2016-1-1', 1), 0
1 , , 2012-12-31 .
3, : weeknumber = 1 month = 12, year + 1 if weekumber = 53 month = 1, - 1
- ?