date statement
Overview
The date statement can be used to display the date and time.
Usage
Function date () is used in different ways. It always returns a string corresponding to what we asked him (hour, day, month, etc. ...).Important: the returned parameters are those returned from the server.
To work, the function requires one or more of the following parameters:
| Char | Meaning | Possible values |
| Day | ||
| j | Day of the month on two digits without leading zeros | 1 to 31 |
| d | Day of the month on two digits with leading zeros | 01 to 31 |
| l | (L tiny) Day of the week (english) | Sunday to Saturday |
| w | Day of week in digital format | 0 (sunday) to 6 (saturday) |
| z | Day of the week | 0 to 366 |
| Week | ||
| W | Week number, for current month (weeks are starting on mondays) | Example : 42 (week 42 of the year) |
| Months | ||
| F | Month, textual | January to December |
| m | Month, in numerical format, with leading zeros | 01 to 12 |
| n | Month, in numerical format, without leading zeros | 1 to 12 |
| t | Number of days, in the month | 28 to 31 |
| Year | ||
| L | Is it a leap year? | 1 if leap, else: 0. |
| Y | Year, with 4 digits | Examples : 1999 and 2003 |
| y | Year, with 2 digits | Examples : 99 and 03 |
| Time | ||
| a | Ante meridian and post meridian (lower) | am or pm |
| A | Ante meridian and post meridian (upper) | AM or PM |
| g | Hour (12h format) without leading zeros | 1 to 12 |
| G | Hour (24h format) without leading zeos | 0 to 23 |
| h | Hour (12h format) with leading zeros | 01 to 12 |
| H | Hour (24h format) with leading zeros | 00 to 23 |
| s | Seconds, with leading zeros | 00 to 59 |
| i | Minutes, with leading zeros | 00 to 59 |
Code Examples:
<?php
echo date('Y'); //Will display current year (4 digits)
?>
<?php
echo date('m').' '.date('Y'); //display the month on two digits and the current year in 4 digits
?>
<?php
echo date('m Y'); //display the month on two digits and the current year in 4 digits
?>
<?php
echo date('m/Y');
?>