Be the first to rate this file! 0 Downloads (last 30 days) File Size: 2.28 KB File ID: #21260

Exact Datevec Second Data

by Patrick Flick

 

29 Aug 2008 (Updated 29 Aug 2008)

This function bypasses the problem with rounded date values, caused by the floating point representa

| Watch this File

File Information
Description

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)

MATLAB release MATLAB 7.3 (R2006b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
01 Sep 2008 Carlos Adrian Vargas Aguilera

Adding 0.25 seconds is not a good idea, but anyway. Have you check DATEVECFIX here at the FileExchange?

Carlos

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
datevec Patrick Flick 22 Oct 2008 10:16:36
datenum Patrick Flick 22 Oct 2008 10:16:36
datetime Patrick Flick 22 Oct 2008 10:16:36
second Patrick Flick 22 Oct 2008 10:16:36
exactdatev Patrick Flick 22 Oct 2008 10:16:36
round Patrick Flick 22 Oct 2008 10:16:36
float Patrick Flick 22 Oct 2008 10:16:36
rounding Patrick Flick 22 Oct 2008 10:16:36
datenum Roger 30 Jan 2009 14:49:29

Contact us at files@mathworks.com