PHP Missing Function In Older Version
- by Umair Ashraf
My this PHP function converts a datetime string into more readable way to represent passed date and time. This is working perfect in PHP version 5.3.0 but on the server side it is PHP version 5.2.17 which lacks this function. Is there a way I can fix this efficiently? This is not only a function which needs this "diff" function but there are many more.
public function ago($dt1)
{
$interval = date_create('now')->diff(date_create($dt1));
$suffix = ($interval->invert ? ' ago' : '-');
if ($v = $interval->y >= 1) return $this->pluralize($interval->y, 'year') . $suffix;
if ($v = $interval->m >= 1) return $this->pluralize($interval->m, 'month') . $suffix;
if ($v = $interval->d >= 1) return $this->pluralize($interval->d, 'day') . $suffix;
if ($v = $interval->h >= 1) return $this->pluralize($interval->h, 'hour') . $suffix;
if ($v = $interval->i >= 1) return $this->pluralize($interval->i, 'minute') . $suffix;
return $this->pluralize($interval->s, 'second') . $suffix;
}