Apoya a Time.now: Únete a nuestro Plan Premium ¡para una experiencia sin anuncios! Apóyanos: ¡Hazte Premium sin anuncios!

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.

Instrucciones paso a paso

  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.

Conviene saber

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.