public function dateDifference($past, $now = "now")
{
// initializes the placeholders for the different "times"
$seconds = 0;
$minutes = 0;
$hours = 0;
$days = 0;
$months = 0;
$years = 0;
// sets the default timezone
date_default_timezone_set($this->timezone);
// finds the past in datetime
$past = strtotime($past);
// finds the current datetime
$now = strtotime($now);
// calculates the difference
$timeDifference = $now - $past;
// starts determining the time difference
if ($timeDifference >= 0) {
switch ($timeDifference) {
// finds the number of years
case $timeDifference >= $this->secondsPerYear:
// uses floor to remove decimals
$years = floor($timeDifference / $this->secondsPerYear);
// saves the amount of seconds left
$timeDifference = $timeDifference - $years * $this->secondsPerYear;
// finds the number of months
// finds the number of months
case $timeDifference >= $this->secondsPerMonth && $timeDifference <= $this->secondsPerYear - 1:
// uses floor to remove decimals
$months = floor($timeDifference / $this->secondsPerMonth);
// saves the amount of seconds left
$timeDifference = $timeDifference - $months * $this->secondsPerMonth;
// finds the number of days
// finds the number of days
case $timeDifference >= $this->secondsPerDay && $timeDifference <= $this->secondsPerYear - 1:
// uses floor to remove decimals
$days = floor($timeDifference / $this->secondsPerDay);
// saves the amount of seconds left
$timeDifference = $timeDifference - $days * $this->secondsPerDay;
// finds the number of hours
// finds the number of hours
case $timeDifference >= $this->secondsPerHour && $timeDifference <= $this->secondsPerDay - 1:
// uses floor to remove decimals
$hours = floor($timeDifference / $this->secondsPerHour);
// saves the amount of seconds left
$timeDifference = $timeDifference - $hours * $this->secondsPerHour;
// finds the number of minutes
// finds the number of minutes
case $timeDifference >= $this->secondsPerMinute && $timeDifference <= $this->secondsPerHour - 1:
// uses floor to remove decimals
$minutes = floor($timeDifference / $this->secondsPerMinute);
// saves the amount of seconds left
$timeDifference = $timeDifference - $minutes * $this->secondsPerMinute;
// finds the number of seconds
// finds the number of seconds
case $timeDifference <= $this->secondsPerMinute - 1:
// seconds is just what there is in the timeDifference variable
$seconds = $timeDifference;
}
}
$difference = array("years" => $years, "months" => $months, "days" => $days, "hours" => $hours, "minutes" => $minutes, "seconds" => $seconds);
return $difference;
}