103 of 110 menu

PHP Time Format

The time format is set by special control commands for the date function. Here are these commands:

  • U – the number of seconds since January 1, 1970 (i.e., timestamp).
  • z – the day of the year (starting from 0).
  • Y – year, 4 digits.
  • y - year, two digits.
  • m – numeric representation of a month (with leading zeros).
  • n – numeric representation of a month (without leading zeros).
  • d – day of the month (with leading zeros).
  • j – day of the month (without leading zeros).
  • w – numeric representation of the day of the week (0 for Sunday, 1 for Monday, etc.).
  • h – hour in 12-hour format.
  • H – hour in 24-hour format.
  • i – minutes.
  • s – seconds.
  • L1 if it's a leap year, 0 otherwise.
  • W – ISO-8601 week number of the year.
  • t – number of days in the given month.

Any separators can be inserted between the commands (hyphens, colons, etc.).

Examples of Using date

<?php // All examples are shown for the date 01.06.2013 at 12.23.59, Monday echo date('Y'); // returns '2013' echo date('y'); // returns '13' echo date('m'); // returns '06' - month number echo date('d'); // returns '01' - day of the month echo date('j'); // returns '1' - day of the month (without leading zero) echo date('w'); // returns '1' - Monday echo date('H'); // returns '12' - hours echo date('i'); // returns '23' - minutes echo date('s'); // returns '59' - seconds echo date('d-m-Y'); // returns '01-06-2013' echo date('d.m.Y'); // returns '01.06.2013' echo date('H:i:s d.m.Y'); // returns '12:23:59 01.06.2013' ?>

See Also

  • the date function,
    which formats a date
English
БеларускаяEspañolРусский
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline