Wednesday, January 23, 2008

Great PHP Datetime Conversion Snippet

Using PHP you can easily convert just about any date or time to the format of your choosing.

function strototime() which accepts English textual datetime strings and outputs timestamps can be combined with the date() function to output a formated date.

For instance,

date("n/j/y",strtotime($someDate))

will accept a datetime of pretty much any format and output it as mm/dd/yyyy.

This can come in handy when working with dates stored in a database as strings or when converting between International and US formats.

No comments: