$lastDateOfMonth = date("Y-m-t", strtotime('2022-08-25')); // 2022-08-01
<?php
//Create DateTime object from specified date.
$date = new DateTime('2012-02-01');
//Print out your desired result by using
//the format method
echo $date->format('Y-m-t');