-2

I'm developing a system that recibe a date format like: yyyy/mm/dd-hh-mm-ss.00 and I need convert it to Y-m-d H:i:s.

What I done was:

$newDate = date("Y-m-d H:i:s", strtotime($values[2]));

where $values[2] it is the date in that format, for instace: 2014/01/01-13-18-23.00. But the result is: 1970-01-01 01:00:00

Can you help me?

Thanks

Juan Jardim
  • 2,202
  • 6
  • 26
  • 46

4 Answers4

2

You can try with strptime like

$format = "%Y-%m-%d %H:%i:%s";
echo strptime($values[2], $format);
Gautam3164
  • 28,027
  • 10
  • 58
  • 83
1

You should be able to do something like this:

$date = DateTime::createFromFormat("Y/M/d-H-i-s.00", $values[2]);
echo $date->format("Y-m-d H:i:s");
Aleks G
  • 54,795
  • 26
  • 160
  • 252
1

Try using DateTime

$date = DateTime::createFromFormat('Y/m/d-H-i-s.00', '2014/01/01-13-18-23.00');
echo $date->format('Y-m-d H:i:s');

See demo here

Nouphal.M
  • 6,320
  • 1
  • 15
  • 27
1

The dateTime format for strtotime() function are predefined and you have to follow the rules to get desired result.

Mixed date time formats are available here PHP: Compound Formats - Manual

itzmukeshy7
  • 2,640
  • 1
  • 20
  • 28