格式日期时间增加1年

I'm use this code:

$my_date_time = DateTime::createFromFormat('m/d/Y H:i', '20/02/2018 00:51')->format('Y-m-d H:i');
echo $my_date_time;

the code should show me this: 2018-02-20 00:51

but show: 2019-02-20 00:51

it increase 1 more year.. why..?

I think you reversed the day and the month when using DateTime::createFromFormat.

Try this format:

d/m/Y

$my_date_time = DateTime::createFromFormat('d/m/Y H:i', '20/02/2018 00:51')->format('Y-m-d H:i'); echo $my_date_time;

Test online