10 of 110 menu

The date Function in PHP

The date function outputs the current date and time in a specified format. The format is defined using control commands, and any separators can be inserted between them (hyphens, colons, and so on).

Here is a list of control commands:

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

Any separators can be inserted between the commands (hyphens, colons, and so on).

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' ?>
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