note 59724 added to function.date

From: Date: Wed, 14 Dec 2005 12:38:24 +0000
Subject: note 59724 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-100122@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,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 ?> ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+59724 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+59724&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+59724&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+59724&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+59724&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+59724&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+59724&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+59724&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+59724&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#100122) next »