PHP Date Function Tips
In this Tutorial you will learn some Tips on PHP Date Functions - formats, syntax and output.
Format with Result | Syntax | Output |
a Displays "am" or "pm" | echo date('d-m-y a'); | 23-04-05 pm |
A Displays "AM" or "PM" | echo date('d-m-y A'); | 23-04-05 PM |
d Displays day of the month with leading 0 that is "01" to "31" | echo date('d'); | 23 |
D Displays day of the week with 3 characters. | echo date('D'); | Sat |
F Displays day of the week with full text. | echo date('d-F-y A'); | 23-April-05 PM |
h Displays the hour format is "01" to "12". | echo date('h A '); | 02 PM |
H Displays the hour format is "01" to "23". | echo date('H A '); | 14 PM |
g Displays the hour without leading 0 format is "1" to "12". | echo date('g A '); | 2 PM |
G Displays the hour without leading 0 format is "0" to "23". | echo date('G A '); | 14 PM |
i Displays the minutes format is "00" to "59". | echo date('H : i A '); | 14 : 34 PM |
j Displays day of the month without leading 0 format is "1" to "31". | echo date('j-m-y'); | 23-04-05 |
l Displays day of the week with long text format is "Friday". | echo date('l-m-y'); | Saturday-04-05 |
L Returns the boolean value whether it is leap year or not. | echo date('l-m-y L'); 0 - False 1 - True |
Saturday-04-05 0 |
m Displays the month format is "01" to "12". | echo date('m'); | 04 |
n Displays the month without leading 0 format is "1" to "12". | echo date('n'); | 4 |
M Displays the month with 3 characters format is "Jan". | echo date('M'); | Apr |
s Displays the seconds "00" to "59". | echo date('s'); | 41 |
S English ordinal suffix with 2 characters "th" "nd". | echo date('d - m - y S'); | 23 - 04 - 05 rd |
t number of days in the given month. | echo date('t'); | 30 |
w shows the numeric value of the day of the week 0(Sunday) to 6(Saturday). | echo date('w l'); | 6 Saturday |
Y shows the year with 4 digits format"2005". | echo date('Y'); | 2005 |
y shows the year with 2 digits format"05". | echo date('y'); | 05 |