Useful Date Formats in PHP

By | May 3, 2008

Often you need to generate a timestamp with PHP. It should represent the current date or the date in the future. It should show the date, month and year in all possible readable formats. I’ve created a list that has most often used date formats. Here it is:

F j, Y
F j, y
F d, Y
F d, y
d-M-Y
d-M-y
j-M-y
j-M-Y
d/n/y
d/m/y
d/n/Y
d/m/Y
j/m/y
j/m/Y
j/n/y
j/n/Y
Y-m-j
Y-n-j
Y-m-d
Y-n-d
n/d/y
m/d/y
n/d/Y
m/d/Y
m/j/y
n/j/y
m/j/Y
n/j/Y
d.m.Y
d.m.y
d.n.Y
d.n.y
j.m.Y
j.n.Y
j.m.y
j.m.y
m-j-Y
n-j-Y
m-d-Y
n-d-Y

Usage is quite simple.

<?
$guess=mktime (0,0,0,date(“m”),date(“d”),date(“Y”));
$data=date($dateformat, $guess);
?>

Just use the date format you like and set the date for formatting (it is set to today by default) and insert this code anywhere you need to have the date displayed in the appropriate format.