1$startDate = new DateTime("2019-10-27");
2$endDate = new DateTime("2020-04-11");
3
4$difference = $endDate->diff($startDate);
5echo $difference->format("%a");
1<?php
2function dateDifference($start_date, $end_date)
3{
4 // calulating the difference in timestamps
5 $diff = strtotime($start_date) - strtotime($end_date);
6
7 // 1 day = 24 hours
8 // 24 * 60 * 60 = 86400 seconds
9 return ceil(abs($diff / 86400));
10}
11
12// start date
13$start_date = "2016-01-02";
14
15// end date
16$end_date = "2016-01-21";
17
18// call dateDifference() function to find the number of days between two dates
19$dateDiff = dateDifference($start_date, $end_date);
20
21echo "Difference between two dates: " . $dateDiff . " Days ";
22?>
1date('Y/m/d',strtotime("-1 days"));
2
3Or Use DateTime class like this-
4
5$date = new DateTime();
6echo $date->modify("-1 days")->format('Y-m-d');