Insert Date using PHP
This little tutorial will be about inserting date and/or time into a webpage using PHP. This is better than using Javascript, because the code is smaller and it doesn't require Javascript to be installed.
To include a date into a webpage, insert this code. The file's extension must be .php.
<? $date = date("l, j F Y");
echo $date;
?>
If you insert this you'll get: Wednesday, 12 November 2025. You can change it of course to with you like. Here's a list with all the available codes.
| Letter | Output |
|---|---|
| a | Gives "am" or "pm". |
| A | Gives "AM" of "PM". |
| B | Swatch Internet time ("000" till "999") |
| d | Day of the Month, from 01 till 31. |
| D | Day of the week, in 3 letters, example Mon, Wed etc. |
| F | Month full out, so "January", "March" etc. |
| g | Hours, in 12-hoursformat, example 4 or 8. |
| G | Hours, in 24-hoursformat, example 8 or 19. |
| h | Hours, in 12-hoursformat, example 04 or 08. |
| H | Hours, in 24-hoursformat, example 08 or 19. |
| i | Minutes, from 01 to 60. |
| I | Displays "1" when Daylight Saving Time, otherwise "0". |
| j | Number of the day of the month, example 1 of 17. |
| l | Day of week full out, for example "Monday", "Wednesday" etc. |
| L | Whether it's a leap year. 1 = Yes, 0 = No. |
| m | Month in number, for example 01 or 10. |
| M | Month in 3 letters, so "Jan" or "Feb". |
| n | Month in numbers, so 1 or 10. |
| O | Difference in Greenwich-time, for example "+0100" of "+0200". |
| r | Full date, example: "Mon, 12 Feb 2003 14:22:50 +0200". |
| s | Seconds, example 01 of 35. |
| S | "st", "nd" of "rd". |
| t | The number of days that the current month has, so 28, 29, 30 or 31. |
| T | Time zone setting of this machine (so CET). |
| U | Seconds since the Unix Epoch. |
| w | Day of the week, in numbers, from 0 to 6 (0 = Sunday). |
| W | ISO-8601 week number of the year, week starts on Monday. |
| y | Year in two numbers, example 01 or 03. |
| Y | Year in four numbers, example 2001 or 2003. |
| z | Day of the year, from 0 to 365. |
| Z | Time zone offset in seconds. |
If you have any problems with this, feel free to contact me by using the contact form.
