Parameter differences between date and strftime PHP functions

First published on August 31, 2012

strftime() has a similar functionality to date(): both functions return formatted date text based on a Unix timestamp, using configurable parameters. strftime() has the advantage of using locale / language specific text, such as a month name, where relevant. date() isn’t solely intended for text output, so it provides some extra parameters, such as whether or not the given year is a leap year.

The two functions share many formatting parameters that are well-documented. However, there are also many differences in equivalent parameters; here are some:

strftime date
Minutes with leading zeros %M %i
Seconds with leading zeros %S %s
Abbreviated day %a %D
Full day %A %l

Be sure to compare the documentation if you’re porting a formatting string between the functions!

For example, to format the current time in the Solr date format using the strftime() function, you would use:

strftime( '%Y-%m-%dT%H:%M:%SZ', time() );

… while the equivalent with date() is:

date( '%Y-%m-%dT%H:%i:%sZ', time() );

Speak your mind

To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word