|
PHP Resources -
Handy PHP Functions
|
|
Written by M. L. Griswold
|
|
Sunday, 03 September 2006 |
|
Description:
|
| |
string reformat_date(string date, string format) |
| |
|
|
| |
This simple little function comes in quite handy when you need to change the format of a date. Simply enter nearly any date format and this function can convert it to your new format. |
| |
|
|
| Function: |
| |
function reformat_date($date, $format){
// Function written by Marcus L. Griswold (vujsa)
// Can be found at http://www.handyphp.com
// Do not remove this header!
$output = date($format, strtotime($date));
return $output;
}
|
| |
|
|
| Usage: |
| |
echo reformat_date("Thur, 03 Aug 2006 03:59:10 -0700", "l, F jS, Y G:i:s O");
|
| |
|
|
Result:
|
| |
Thursday, August 3rd, 2006 6:59:10 -0400 |
| |
|
|
Notes:
|
| |
This will work for most English date formats. It is only limited by the limitations of the PHP function strtotime().
|
Discuss this article on the forums. (3 posts)
|