Week numbers in MySQL
How to get the week number from a date
To get the ISO week number (1-53) from a date in the column
datecol) FROM …
To get the corresponding four-digit year, use
datecol, 3) DIV 100 FROM …
Read more about
WEEKOFYEAR() and YEARWEEK() in the MySQL manual. How to get the number of weeks in a year
To get the number of ISO weeks (i.e. the number of the last week) in a year, get the week number of 28 December in that year using the above logic, i.e.
yearcol, '-12-28')) FROM …
This is based on the fact that the last week of the year always includes 28 December.
Week numbers in …
A lot of software that deal with dates has poor support for week number, in particular the ISO week numbering scheme that is used on this site.
The concept of week numbers is virtually unknown in large parts of the world, so adding support for them is not high on the agenda for most software companies.
However, with a few tricks it is often possible to make week numbers calculations, even if the application does not have native support for week numbers.
These pages explain how to use week numbers in various popular software applications and programming languages.