Adding/Subtracting no. of days to given date using PHP.
//Capturing today's date
$date = date('Y-m-d');
// logic to calculate date -7 days from $date. Update the -7 days as per your requirement.
$newDate=date_create($date)->modify('-7 days')->format('Y-m-d');
echo $newDate;
/*
Output: Eg. $date is 2021-03-20.
Hence $newDate will be 2021-03-13
*/
Comments
Post a Comment