Exact Datevec Second Data

Version 1.0.0.0 (1002 Bytes) by Patrick Flick
This function bypasses the problem with rounded date values, caused by the floating point representa
685 Downloads
Updated 29 Aug 2008

No License

This function bypasses the problem with rounded date values, caused by the floating point representation of the datetime.

If you do datevec(datenum([ 0 0 0 0 1 0 ])) in Matlab it returns [ 0 0 0 0 0 59.999999999999993 ], which can be annoying when, for example, adding a datenum value for 1 minute to a datenum value for 12:23:00 resulting in 12:23:59.999... Now even rounding doesn't help you as it returns 12:23:60 instead of 12:24:00.

If you use this function: exactDatevecSecondData(datenum([ 0 0 0 0 1 0 ])) it returns [ 0 0 0 0 1 0 ], making it the solution to the previous example as it returns 12:24:00.

NOTICE: This function fails if you are working with higher precision then seconds (e.g. milliseconds)

Cite As

Patrick Flick (2024). Exact Datevec Second Data (https://www.mathworks.com/matlabcentral/fileexchange/21260-exact-datevec-second-data), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2006b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
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!
Version Published Release Notes
1.0.0.0