You can use t
in format specifier on DateTime
‘s format
function.
format character: t
Description: Number of days in the given month
Example returned values: 28 through 31
<?php
$input="2017-08-28 10:50:30";
$date_time = DateTime::createFromFormat('Y-m-d H:i:s', $input);
$last_day_of_month = $date_time->format('Y-m-t H:i:s');
echo $last_day_of_month;
This gives:
2017-08-31 10:50:30
Demo: https://eval.in/844314
0
solved Call to member function setDate() on string