function date_format_interval in Date 5.2
Same name and namespace in other branches
- 8 date_api/date_api.module \date_format_interval()
- 6.2 date_api.module \date_format_interval()
- 6 date_api.module \date_format_interval()
- 7.3 date_api/date_api.module \date_format_interval()
- 7 date_api/date_api.module \date_format_interval()
- 7.2 date_api/date_api.module \date_format_interval()
An override for interval formatting that adds past and future context
Parameters
DateTime $date:
integer $granularity:
Return value
formatted string
1 call to date_format_interval()
- date_formatter_process in date/
date.module - Helper function for creating formatted date arrays from a formatter.
File
- ./
date_api.module, line 559 - This module will make the date API available to other modules. Designed to provide a light but flexible assortment of functions and constants, with more functionality in additional files that are not loaded unless other modules specifically include them.
Code
function date_format_interval($date, $granularity = 2) {
$interval = time() - date_format($date, 'U');
if ($interval > 0) {
return t('!time ago', array(
'!time' => format_interval($interval, $granularity),
));
}
else {
return format_interval(abs($interval), $granularity);
}
}