Over the past few months I have been working on time and Dates functions for my works and was finding it a little confusing at first as I didn’t find any easy reference for Dates & Time formatting in PHP. I did thought of making a reference table from the time I was redesigning my blog but couldn’t due to some or the other reason any way here it is

I did work a little on managing Time Zones with PHP but I skipped to make a cheat sheet for formatting using PHP date() function. The date/time functions allow you to get the date and time from the server and also to format the date and time in several ways.

", )

The date() function takes in 2 arguments, first is formatting string that is what this article is about and the second a UNIX timestamps, that is time in the number of seconds since the Unix Epoch.

Note : PHP will give a warning not to rely on the system’s timezone settings if you haven’t set time Zone refer Time Zones with PHP to set it.

The following is a reference table of common PHP dates, time stamp used for demo is 1425539844.

Date String Output Comment
Y-m-d H:i:s 2015-03-05 07:17:24 MySQL DATETIME format
H:i:s 07:17:24 Time in Hour, Minuet’s and seconds
d-m-y 05-03-15 Date in Day, Month and Year (2 digits)
d-m-Y 05-03-2015 Date in Day, Month and Year ( 4 Digits )
jS 5th Numeric contractions for ordinals
l dS F Y Thursday 05th March 2015 Expanded human laymen readable form

If you want to try out the values with a custom time stamp check out the demo.

Demo Github