note 59724 modified in function.date by vrana
| From: | vrana@php.net | Date: | Wed, 08 Feb 2006 15:14:38 +0000 |
| Subject: | note 59724 modified in function.date by vrana | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-103314@lists.php.net to get a copy of this message | ||
My function (http://phpshortcuts.blog-city.com/dateconvert_1.htm
) for converting system dates into user-friendly dates depending on the scenario in which it's
used:
<?
function DateConvert($old_date, $layout)
{
//Remove non-numeric characters that might exist (e.g. hyphens and colons)
$old_date = ereg_replace('[^0-9]', '', $old_date);
//Extract the different elements that make up the date and time
$_year = substr($old_date,0,4);
$_month = substr($old_date,4,2);
$_day = substr($old_date,6,2);
$_hour = substr($old_date,8,2);
$_minute = substr($old_date,10,2);
$_second = substr($old_date,12,2);
//Combine the date function with mktime to produce a user-friendly date & time
$new_date = date($layout, mktime($_hour, $_minute, $_second, $_month, $_day, $_year));
return $new_date;
}
?>
The function is then called like this:
<?
$todays_date = "2005-07-01 12:35:01";
//We can use words to desccribe the date (as you see on on my blog)
print DateConvert($todays_date, "l, jS F Y");//Friday, 1st July 2005
//We can use the UK style
print DateConvert($todays_date, "d/m/Y");//01/07/2005
//We can use the US style
print DateConvert($todays_date, "Y/m/d");//2005/07/01
//We can even add the time
print DateConvert($todays_date, "Y/m/d - g:ia");//2005/07/01 12:35pm
?>
--was--
My function (http://phpshortcuts.blog-city.com/dateconvert_1.htm
) for converting system dates into user-friendly dates depending on the scenario in which it's
used:
<?
function DateConvert($old_date, $layout)
{
//Remove non-numeric characters that might exist (e.g. hyphens and colons)
$old_date = ereg_replace('[^0-9]', '', $old_date);
//Extract the different elements that make up the date and time
$_year = substr($old_date,0,4);
$_month = substr($old_date,5,2);
$_day = substr($old_date,8,2);
$_hour = substr($old_date,11,2);
$_minute = substr($old_date,14,2);
$_second = substr($old_date,17,2);
//Combine the date function with mktime to produce a user-friendly date & time
$new_date = date($layout, mktime($_hour, $_minute, $_second, $_month, $_day, $_year));
return $new_date;
}
?>
The function is then called like this:
<?
$todays_date = "2005-07-01 12:35:01";
//We can use words to desccribe the date (as you see on on my blog)
print DateConvert($todays_date, "l, jS F Y");//Friday, 1st July 2005
//We can use the UK style
print DateConvert($todays_date, "d/m/Y");//01/07/2005
//We can use the US style
print DateConvert($todays_date, "Y/m/d");//2005/07/01
//We can even add the time
print DateConvert($todays_date, "Y/m/d - g:ia");//2005/07/01 12:35pm
?>
http://php.net/manual/en/function.date.php