Created
August 1, 2019 13:54
-
-
Save madgrk/70b0de0d797337890dd702fccc1338b5 to your computer and use it in GitHub Desktop.
Show Difference In Days Between Two Dates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class DifferenceInDays { | |
private $difference; | |
protected $start; | |
protected $end; | |
function __construct($startDateTime, $endDateTime) { | |
if (is_string($startDateTime)) | |
$this->start = date_create($startDateTime); | |
if (is_string($endDateTime)) | |
$this->end = date_create($endDateTime); | |
} | |
public function GetDifferenceInDays() { | |
$this->difference = date_diff($this->start, $this->end); | |
$total = $this->difference->y * 365.25 + $this->difference->m * 30 + $this->difference->d + $this->difference->h / 24 + $this->difference->i / 60; | |
return ($this->difference->invert) ? -1 * $total : $total; | |
} | |
} | |
$obj = new DifferenceInDays('2011-01-01', '2011-01-23'); | |
print $obj->GetDifferenceInDays() . "\n"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment