How can I convert this string 05/Feb/2010:14:00:01
to unixtime ?
This question is related to
php
string
unix-timestamp
If it's a string that you trust meaning that you have checked it before hand then the following would also work.
$date = new DateTime('2015-03-27');
Try this:
$new_date=date('d-m-Y', strtotime($date));
$d="05/Feb/2010:14:00:01";
$dr= date_create_from_format('d/M/Y:H:i:s', $d);
echo $dr->format('Y-m-d H:i:s');
here you get date string, give format specifier in ->format() according to format needed
You should look into the strtotime() function.
Simple exploding should do the trick:
$monthNamesToInt = array('Jan'=>1,'Feb'=>2, 'Mar'=>3 /*, [...]*/ );
$datetime = '05/Feb/2010:14:00:01';
list($date,$hour,$minute,$second) = explode(':',$datetime);
list($day,$month,$year) = explode('/',$date);
$unixtime = mktime((int)$hour, (int)$minute, (int)$second, $monthNamesToInt[$month], (int)$day, (int)$year);
If you're up for it, use the DateTime class
Use the strtotime
function:
Example:
$date = "25 december 2009";
$my_date = date('m/d/y', strtotime($date));
echo $my_date;
Source: Stackoverflow.com