I'm using regex to get date time from a string in proper format.
if string is 2/12/2013 2 : 31 AM then i use below code to remove spaces before and after : to get 2/12/2013 2:31 AM
$dtTime = preg_replace('/(\s+\:\s+)/', ':', $dtTime);
But what to do when string is 2/12/2013 2 31 AM to get 2/12/2013 2:31 AM?
I tried to use below code but not worked
$dtTime = preg_replace('/[^\/0-9](\d+\s\d+)/', ':', $dtTime)
Note that date may be separated by / or -
Purpose of above code is to get date and time separately from a string by:
$dtime = strtotime($dtTime);
$rtime = date('H:i:s',$dtime); // 08:50:05
$rdate = date('Y-m-d',$dtime);
$dtime = strtotime($dtTime); $rtime = date('H:i:s',$dtime); $rdate = date('Y-m-d',$dtime);