-6

I have the following data available : 01/02/2014

What I need to format to is: 2014-01-02 00:00:00

What is the best way to do this in PHP?

John Conde
  • 217,595
  • 99
  • 455
  • 496
somejkuser
  • 8,856
  • 20
  • 64
  • 130

4 Answers4

4
$dt = DateTime::createFromFormat('m/d/Y', '01/02/2014');
echo $dt->format('Y-m-d 00:00:00');

See it in action

John Conde
  • 217,595
  • 99
  • 455
  • 496
2
$val="01/02/2014";
echo  date("Y-m-d H:i:s", strtotime($val));

Demo

Nambi
  • 11,944
  • 3
  • 37
  • 49
2

First of all you should try it yourself.
you should study php date format documentation : http://www.php.net/manual/en/datetime.formats.date.php
Live demo: https://eval.in/93149

$d = "01/02/2014";

echo date('Y-m-d H:i:s',strtotime($d));

OUTPUT:

2014-01-02 00:00:00
Awlad Liton
  • 9,366
  • 2
  • 27
  • 53
0

By using PHP date function

$date = "1st April 2000";

OR

$date = "01/04/2000";

echo date("Y-m-d H:i:s",strtotime($date));
Mukilan R
  • 445
  • 5
  • 17