Deoctor Posted February 5, 2010 Share Posted February 5, 2010 How do i convert date of this format Friday 5th of February 2010 10:54:01 AM to something like this 02/05/2010 Link to comment https://forums.phpfreaks.com/topic/191015-date-conversion/ Share on other sites More sharing options...
Irvin Amoraal Posted February 5, 2010 Share Posted February 5, 2010 Need more information. How/where do you get the date? What are you using it for. Look at the php manual for date strings: http://php.net/manual/en/function.date.php Also found this Googling php date format: <?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". Hope this helps. Link to comment https://forums.phpfreaks.com/topic/191015-date-conversion/#findComment-1007263 Share on other sites More sharing options...
Deoctor Posted February 5, 2010 Author Share Posted February 5, 2010 Dear Irvon ur function does not work.. as strptime is not a valid php function. and for the info u require i am getting the date value as like this.. date('l jS \of F Y h:i:s A') i have checked the php manual but didnt found any solution for my issue. :'( Can some one help me out on this.. Link to comment https://forums.phpfreaks.com/topic/191015-date-conversion/#findComment-1007271 Share on other sites More sharing options...
jl5501 Posted February 5, 2010 Share Posted February 5, 2010 <?php $indate = 'Friday 5th of February 2010 10:54:01 AM'; $datebits = explode(" ",$indate); $indate2 = (int)$datebits[1].' '.$datebits[3].' '.$datebits[4]; echo strftime("%m/%d/%Y",strtotime($indate2)); ?> Link to comment https://forums.phpfreaks.com/topic/191015-date-conversion/#findComment-1007282 Share on other sites More sharing options...
Deoctor Posted February 5, 2010 Author Share Posted February 5, 2010 Cool reply thank you dude.. Link to comment https://forums.phpfreaks.com/topic/191015-date-conversion/#findComment-1007290 Share on other sites More sharing options...
Irvin Amoraal Posted February 5, 2010 Share Posted February 5, 2010 Try one of these: <?php echo date("Y/m/d") . "<br />"; echo date("Y.m.d") . "<br />"; echo date("Y-m-d") ?> Irvin. <>< Link to comment https://forums.phpfreaks.com/topic/191015-date-conversion/#findComment-1007492 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.