Formatting Dates in PHP

Do you need to format dates using php? Well, it's easy as cake - read on for some example code.

If you are looking for it to spit out the mm/dd/yyyy format, this is how it's done.


// just spits out the current month/day/year, and that's the full 4 digit year
echo date('m/d/Y');

// if you want it to also display time, you can do this
echo date('m/d/Y H:i:s');

// all of that displays the current time, but if you're looking for a specific time to format, you can pass epoch time in seconds as the second parameter in date - that time should be 08/20/2012 22:51:37
$seconds = '1345503097';
echo date('m/d/Y H:i:s', $seconds);

For more information on the format characters, check out the official PHP Date page.

jon | August 20, 2011 | Comments (0)

Comments

No comments yet, but you can be the first to post!

Name (required)
Email (will not be published) (required)
Website

captcha