Skip to content

Instantly share code, notes, and snippets.

@ternarybit
ternarybit / time_delta.php
Created May 11, 2011 23:14
Express difference between two timestamps in various English time units
/*
time_delta() returns the difference between two times
expressed in many ways.
(mixed) $start: The initial time to calculate from
(mixed) $target: The time in the past or future to calculate the difference between
(int) $precision:
0: Generic - ex. "About 7 hours ago"
1: Approximate - ex. "7 hours, 15 minutes ago"
2: Exact - ex. "7 hours, 15 minutes and 6 seconds ago"