Convert seconds to human readable string(s)

Convert an amount of seconds to hours/days/weeks/etc.


Updated 2 May 2020

From GitHub

View License on GitHub

Editor's Note: This file was selected as MATLAB Central Pick of the Week

This function converts a (usually large) amount of seconds to human-readable string. For example,
>> str = seconds2human(1463456.3)
str =
'About 2 weeks and 2 days.'
You may also call the function with a second input argument; either 'short' (the default) or 'full'. This determines the level of detail returned in the string:
>> str = seconds2human(1463456.3, 'full')
str =
'2 weeks, 2 days, 22 hours, 30 minutes, 56 seconds.'

The 'short' format returns only the two largest units of time.

Furthermore, [secs] may be an NxM-matrix, in which case the output is an NxM cell array of the corresponding strings.

Cite As

Rody Oldenhuis (2023). Convert seconds to human readable string(s) (, GitHub. Retrieved .

MATLAB Release Compatibility
Created with R2009b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Find more on Dates and Time in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Versions that use the GitHub default branch cannot be downloaded

Version Published Release Notes

See release notes for this release on GitHub:

Description update
[linked to Github]

- Added 'decennium' as a time unit
- Implemented more robust error-checking
- Small documentation update

Updated contact info

- reduced the default verbosity, as suggested by Jos. The verbosity can now be changed with a second argument.

- Included (sec < 1) case, as suggested by Jesse.

updated code thanks to Jos' comments.

To view or report issues in this GitHub add-on, visit the GitHub Repository.
To view or report issues in this GitHub add-on, visit the GitHub Repository.