Possible Duplicate:
Getting time and date from timestamp with php
I am trying to convert this date format:
09/14/2012 10:11
into this other standard timestamp format:
2012-09-14 09:44:54
What is the most efficient way of doing it?
Possible Duplicate:
Getting time and date from timestamp with php
I am trying to convert this date format:
09/14/2012 10:11
into this other standard timestamp format:
2012-09-14 09:44:54
What is the most efficient way of doing it?
You can use PHP's date
and strtotime
functions:
$date = '09/14/2012 10:11';
$formatted = date('Y-m-d H:i:s', strtotime($date));
You can use DateTime object
$date = DateTime($myDate);
or your custom input format with createFromFormat
$date = DateTime::createFromFormat('d/m/y H:i:s', $myDate);
format Will make your output
$result = $date->format('Y-m-d H:i:s');
date('Y-m-d H:i:s', strtotime('09/14/2012 10:11'));
Though it's going to be hard to change the time.
Convert first into timestamp with strtotime
and convert timestamp into date with date
.
$outputDate = date( 'Y-m-d H:i:s', strtotime( $inputDate ));