1<?php
2// PHP program to add days to $Date
3
4// Declare a date
5$date = "2019-05-10";
6
7// Add days to date and display it
8echo date('Y-m-d', strtotime($date. ' + 10 days'));
9
10?>
1<?php
2$stop_date = '2009-09-30 20:24:00';
3echo 'date before day adding: ' . $stop_date;
4$stop_date = date('Y-m-d H:i:s', strtotime($stop_date . ' +1 day'));
5echo 'date after adding 1 day: ' . $stop_date;
6?>
1//get Date diff as intervals
2$d1 = new DateTime("2018-01-10 00:00:00");
3$d2 = new DateTime("2019-05-18 01:23:45");
4$interval = $d1->diff($d2);
5$diffInSeconds = $interval->s; //45
6$diffInMinutes = $interval->i; //23
7$diffInHours = $interval->h; //8
8$diffInDays = $interval->d; //21
9$diffInMonths = $interval->m; //4
10$diffInYears = $interval->y; //1
11
12//or get Date difference as total difference
13$d1 = strtotime("2018-01-10 00:00:00");
14$d2 = strtotime("2019-05-18 01:23:45");
15$totalSecondsDiff = abs($d1-$d2); //42600225
16$totalMinutesDiff = $totalSecondsDiff/60; //710003.75
17$totalHoursDiff = $totalSecondsDiff/60/60;//11833.39
18$totalDaysDiff = $totalSecondsDiff/60/60/24; //493.05
19$totalMonthsDiff = $totalSecondsDiff/60/60/24/30; //16.43
20$totalYearsDiff = $totalSecondsDiff/60/60/24/365; //1.35
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$now = time(); // or your date as well
2$your_date = strtotime("2010-01-31");
3$datediff = $now - $your_date;
4
5echo round($datediff / (60 * 60 * 24));
1<?php
2/**
3 * array _date_diff(string)
4 * function to get the difference between the date you enter and today, in days, months, or years.
5 * @param string $mydate
6 * @return array
7 */
8function _date_diff($mydate) {
9 $now = time();
10 $mytime = strtotime(str_replace("/", "-", $mydate)); // replace '/' with '-'; to fit with 'strtotime'
11 $diff = $now - $mytime;
12 $ret_diff = [
13 'days' => round($diff / (60 * 60 * 24)),
14 'months' => round($diff / (60 * 60 * 24 * 30)),
15 'years' => round($diff / (60 * 60 * 24 * 30 * 365))
16 ];
17 return $ret_diff;
18}
19
20// example:
21var_dump(_date_diff('2021-09-11'));