I have two dates, which I need to know if the difference time does not exceed 72 hours between them. Including the seconds
Reading the Documentation of PHP I found that date_diff()
was the solution for this, but it returns time in separate ways like this:
DateInterval {#1410 ▼
interval: + 4d 10:42:00.0
+"y": 0
+"m": 0
+"d": 4
+"h": 10
+"i": 42
+"s": 0
+"f": 0.0
+"weekday": 0
+"weekday_behavior": 0
+"first_last_day_of": 0
+"invert": 0
+"days": 4
+"special_type": 0
+"special_amount": 0
+"have_weekday_relative": 0
+"have_special
So I use a format to get the time, but I also need a format to unite the hours and the seconds, this is my function
public function compare(){
return $diff = (date_diff(new DateTime('2020-12-24T00:00:00'),new DateTime('2020-12-28T10:42:00')));
$diff = $interval->format('%h')+(($interval->format('%d')*24)+($interval->format('%m')*28*24)+($interval->format('%y')*365*28*24))*3600;
}