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

Week numbers in PHP

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

echo date("W"); // "W" format character returns ISO-8601 week number

* 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. Use the date() function with the W format character: echo date("W");
  2. For a specific date, create a DateTime and call $date->format("W").
  3. Cast the result to an integer to drop the leading zero if needed.

Good to Know

PHP's "W" is ISO 8601 compliant out of the box. Pair it with the "o" format character (ISO year) instead of "Y" when building week labels, to stay correct across the year boundary.