chap
chap

Reputation: 1869

DateTime:createFromFormat creates wrong year and month from date

Passing the following date into the method: 1/13/2016 10:18:20 gives the following 2017-01-01 10:18:20

$time = DateTime::createFromFormat('j/n/Y H:i:s', $row->last_updated);

echo $time->format('Y-m-d H:i:s');

Upvotes: 0

Views: 430

Answers (1)

Rakesh Sojitra
Rakesh Sojitra

Reputation: 3658

You need to create format like below because there is no month with 13

$time = DateTime::createFromFormat('n/j/Y H:i:s', $row->last_updated);
echo $time->format('Y-m-d H:i:s');

Upvotes: 1

Related Questions