image thumbnail


version (3.71 KB) by Marc Jakobi
Class for time stamps in the UNIX format


Updated 14 Oct 2016

View License

DATEUNIX Class for time stamps in the UNIX format (number of seconds
since 01-Jan-1970)

The constructor method can be used to convert datenum, datevec,
datestr and datetime by calling:

dout = dateunix(din)
dout = dateunix(din, formatOut)

It can also be converted to the 4 aforementioned formats by calling
their respective functions on a variable of type dateunix.


- Add/subtract time to a dateunix variable:

newtime = addtime(oldtime, increment);

increment can be 'nanoseconds', 'microseconds', 'milliseconds',
'seconds', 'minutes' or the default: 'days'

- Determine day of the year (value between 1 and 366)

doy = dayofyear(time);

- Determine day of the week (value between 1 and 7)

dow = dayofweek(time, start);
--> start is a string that determines the first day of the week
can be 'Sun' (default), 'Mon', 'Tue', 'Wed', 'Thu', 'Fri',
or 'Sat'

- Determine time of the day in 'nanoseconds', 'microseconds', 'milliseconds',
'seconds' (default), 'minutes' or 'days' (set by input: increment)

tod = timeofday(time, increment);

Methods will be gradually added/updated if they are needed.

Author: Marc Jakobi, 05.10.2016

Cite As

Marc Jakobi (2022). dateunix (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2016b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!