Render an elapsed time string
If the $stop
argument is omitted then it is assumed to be the current time. The maximum period used is weeks, as months and years are not fixed length periods.
Available since version 3.0.129.
Example
$start = '2023-09-08 08:33:52';
$stop = '2023-09-09 10:47:23';
// Regular: 1 day 2 hours 13 minutes 31 seconds
echo $datetime->elapsedTimeStr($start, $stop);
// Abbreviated: 1 day 2 hrs 13 mins 31 secs
echo $datetime->elapsedTimeStr($start, $stop, true);
// Abbreviated with exclusions: 1 day 2 hrs
echo $datetime->elapsedTimeStr($start, $stop, true, [ 'exclude' => 'minutes seconds' ]);
// Optional 3.0.227+ usage and inclusions: 26 hours 13 minutes
echo $datetime->elapsedTimeStr($start, [ 'stop' => $stop, 'include' => 'hours minutes' ]);
Usage
// basic usage
$string = $datetime->elapsedTimeStr($start);
// usage with all arguments
$string = $datetime->elapsedTimeStr($start, $stop = null, $abbreviate = false, array $options = []);
Arguments
Name | Type(s) | Description |
---|---|---|
start | int, string | Starting timestamp or date/time string. |
stop (optional) | int, string, array | Ending timestamp or date/time string, omit for “now”, or:
|
abbreviate (optional) | bool, int, array |
|
options (optional) | array | Additional options:
|
Return value
string
array
Returns array only if the getArray
option is true, otherwise returns a string.
$datetime methods and properties
API reference based on ProcessWire core version 3.0.236