note 90966 added to function.strftime

From: Date: Mon, 18 May 2009 22:12:44 +0000
Subject: note 90966 added to function.strftime
Groups: php.notes 
Request: Send a blank email to php-notes+get-155703@lists.php.net to get a copy of this message
This is so simple it has to be found in one of all the comments on all those different time functions. But since I didn't find it, here it is: Use this to convert between different time formats: <?PHP if (!function_exists('convertTime')) { /** Converts time strings from one format into another using * PHP formats. * * @param String $dformat Format to convert to * @param String $sformat Format to convert from, e.g. format * of $ts * @param String $ts Time string to be converted * @return String Supplied time translated to the format specified * in $dformat */ function convertTime($dformat,$sformat,$ts) { extract(strptime($ts,$sformat)); return strftime($dformat,mktime( intval($tm_hour), intval($tm_min), intval($tm_sec), intval($tm_mon)+1, intval($tm_mday), intval($tm_year)+1900 )); } } /* * And for the test.... */ echo convertTime('%Y-%m-%d','%d.%m.%Y','27.11.2009'); ?> This should print "2009-27-11". I did not put much effort in this code. The task also seems "too simple to be neccessary". But as I said, I didn't find anything to help me with this. Cheers, Michael Z ---- Server IP: 212.124.37.9 Probable Submitter: 85.182.79.247 ---- Manual Page -- http://www.php.net/manual/en/function.strftime.php Edit -- https://master.php.net/note/edit/90966 Del: integrated -- https://master.php.net/note/delete/90966/integrated Del: useless -- https://master.php.net/note/delete/90966/useless Del: bad code -- https://master.php.net/note/delete/90966/bad+code Del: spam -- https://master.php.net/note/delete/90966/spam Del: non-english -- https://master.php.net/note/delete/90966/non-english Del: in docs -- https://master.php.net/note/delete/90966/in+docs Del: other reasons-- https://master.php.net/note/delete/90966 Reject -- https://master.php.net/note/reject/90966 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#155703) next »