note 59724 deleted from function.date by derick

From: Date: Sun, 11 Jun 2006 11:41:34 +0000
Subject: note 59724 deleted from function.date by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-114243@lists.php.net to get a copy of this message
Note Submitter: abu_aaminah at yahoo dot co dot uk ---- 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 ?>

« previous php.notes (#114243) next »