<?php
$date = "20230730";
$newdate = date("M-y", strtotime ( '-1 month' , strtotime ( $date ) )) ;
echo $newdate;
?>
output: Jun-23
same we do with date 31 july :
<?php
$date = "20230731";
$newdate = date("M-y", strtotime ( '-1 month' , strtotime ( $date ) )) ;
echo $newdate;
?>
output: Jul-23
Based on the days in the month how to find correct last month as the answer in this is coming wrong if days in the month are 31.
how to find same answer in PHP carbon library .