I am trying to replace the current day with the last day of the month but the error returns
Call to member function setDate() on string
on the last line. Everything is working correctly except for the setDate function
//current date which is 2017-08-28 10:50:30
$string = $date1;
$dateM = DateTime::createFromFormat("Y-m-d H:i:s", $string);
//getting the day of the month which is 28
$dateMonth = $dateM->format("d");
//if the day is 28
if($dateMonth >= 28){
//change the day to 31
$dateMonth = 31;
//current date which is 28/08/2017
$out = $date1;
//replace 28 with 31
$date1 = $out->setDate($out->format('Y'), $out->format('m'), $dateMonth , $out->format('H'), $out->format('i'), $out->format('s'));
}