โญ Support Time.now: Join our Premium Plan for an ad-free experience! โญ Support Us: Go Premium Ad-Free!

Week numbers in MySQL

To get the current ISO 8601 week number in MySQL, use the following code snippet:

SELECT WEEK(NOW(), 3); -- Mode 3 is ISO-8601

* Ensure your system or application regional settings are set to follow ISO 8601 standards (weeks start on Monday) if the output varies.

Step-by-Step Instructions

  1. Run: SELECT WEEK(NOW(), 3);
  2. Mode 3 means: weeks start Monday and week 1 is the first week with more than 3 days, which is the ISO 8601 rule.
  3. For week labels across year boundaries use YEARWEEK(NOW(), 3), which returns e.g. 202630.

Good to Know

MySQL's default WEEK() mode is 0 (Sunday start, US-style) and its default depends on the default_week_format server variable, so always pass mode 3 explicitly for ISO numbers.