0

I have date in format like 23:44 01.03.2016, I need to format it to: Y-m-d H:i:s.

Here is what I try:

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

where $date is 23:44 01.03.2016.

The code returns 1970-01-01 01:00:00. I've also tried different dates, similar outcome. How to solve this?

Thanks!

Ali
  • 2,993
  • 3
  • 19
  • 42
dreamPr
  • 321
  • 1
  • 2
  • 14

1 Answers1

0

Maybe you can try this:

$date = new DateTime('23:44 01.03.2016');
echo $date->format('Y-m-d H:i:s');


for more details on the object DateTime check this

Sachin
  • 2,627
  • 1
  • 19
  • 35