[php] Convert this string to datetime

Possible Duplicate:
PHP: Convert uncommon date format to timestamp in most efficient manner possible?

How to convert this string to datetime format? 06/Oct/2011:19:00:02

I tried this but it doesn't work.

$s = '06/Oct/2011:19:00:02';

$date = strtotime($s);
echo date('d/M/Y:H:i:s', $date);

This question is related to php

The answer is


Use DateTime::createFromFormat

$date = date_create_from_format('d/m/Y:H:i:s', $s);
$date->getTimestamp();

The Problem is with your code formatting,

inorder to use strtotime() You should replace '06/Oct/2011:19:00:02' with 06/10/2011 19:00:02 and date('d/M/Y:H:i:s', $date); with date('d/M/Y H:i:s', $date);. Note the spaces in between.

So the final code looks like this

$s = '06/10/2011 19:00:02';
$date = strtotime($s);
echo date('d/M/Y H:i:s', $date);