-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,232
  • 6
  • 28
  • 46

4 Answers4

2

You can try with strptime like

$format = "%Y-%m-%d %H:%i:%s";
echo strptime($values[2], $format);
GautamD31
  • 28,552
  • 10
  • 64
  • 85
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
  • 56,435
  • 29
  • 168
  • 265
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,304
  • 1
  • 17
  • 28
0

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,669
  • 1
  • 21
  • 29