Home > PHP > Federico Cargnelutti’s Blog: Format a time interval with the requested granularity

Federico Cargnelutti’s Blog: Format a time interval with the requested granularity

Federico Cargnelutti has posted a class (DateIntervalFormat) that gives you the difference between a date and “now” in words rather than an integer.

This class, a refactored version of Drupal’s format_interval function, makes it relatively easy to format an interval value. The format will automatically format as compactly as possible. For example: if the difference between the two dates is only a few hours and both dates occur on the same day, the year, month, and day parts of the date will be omitted.

So, instead of getting a value of “86400 seconds” you’d get back something like “5 days 3 hours”.

Related posts

Categories: PHP Tags:
  1. No comments yet.


[Federico Cargnelutti’s Blog: Format a time interval with the requested granularity]