0

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?

Community
  • 1
  • 1
Amy Neville
  • 10,067
  • 13
  • 58
  • 94

4 Answers4

3

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));
newfurniturey
  • 37,556
  • 9
  • 94
  • 102
2

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');
Maks3w
  • 6,014
  • 6
  • 37
  • 42
1
date('Y-m-d H:i:s', strtotime('09/14/2012 10:11'));

Though it's going to be hard to change the time.

FrankieTheKneeMan
  • 6,645
  • 2
  • 26
  • 37
1

Convert first into timestamp with strtotime and convert timestamp into date with date.

$outputDate = date( 'Y-m-d H:i:s', strtotime( $inputDate ));
doktorgradus
  • 627
  • 1
  • 5
  • 13