Is there a function to santize a date vector?

1 view (last 30 days)
Hi all,
I was wondering if there's a function to sanitize a date vector (or add a time in seconds to a date vector). For example, if I want to find the date and time 1 millions seconds in the future:
present = datevec(now);
look_ahead = 1e6; % fast forward 1 million seconds
% the date vector for the future
future = present;
future(end) = future(end) + look_ahead;
% print the date one million seconds in the future
future_str = datestr(future) % not what's intended
% Work around it by converting look_ahead to a time stamp.
% This work around is "clunky", loses precision, and is not guaranteed to be correct
look_ahead_stamp = look_ahead / (24*60*60); % if only all days had the same number of seconds
future_str = datestr(datenum(present) + look_ahead_stamp)
% Ideal Solution:
future = SantizeDateVec(future); % does this function exist?
datestr(future)
Any suggestions on the above would be appreciated,
Cheers, Andrew

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 21 Mar 2014
future = datevec(addtodate(now,1e6,'sec'));

More Answers (0)

Categories

Find more on Dates and Time in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!