Code covered by the BSD License  

Highlights from
DateConvert

Be the first to rate this file! 4 Downloads (last 30 days) File Size: 5.06 KB File ID: #25594
image thumbnail

DateConvert

by Jan Simon

 

16 Oct 2009 (Updated 02 Jul 2010)

Simple but fast date conversion: 1.3% of DATESTR time, 20% of DATEVEC/ DATENUM time

| Watch this File

File Information
Description

DateConvert: Simple but fast date conversion

DateConvert converts the DATESTR(0) format to a date vector or serial date number and backwards.

Matlab's DATENUM, DATEVEC and DATESTR accept a variety of inputs, but in consequence they are slow. If the input format is exactly known, the conversion can be much faster:
  DATENUM('17-Oct-2009 11:08:23'): 2.97 sec
  DateConvert('17-Oct-2009 11:08:23', 'number'): 0.039 sec
  => 1.3% (1000 loops, 1.5GHz Pentium-M, Matlab 7.7)

DateConvert does *not* validate the input date as Matlab's date functions:
  DATEVEC('32-Feb-2008 25:62:63') replies [2008 3 4 2 2 7],
  DateConvert('32-Feb-2008 25:61:67' , 'vector') replies [2008 2 32 25 61 67] !
So DateConvert is nearly trivial, but optimized for speed. I needed it for sorting 200'000 time stamps and reduced the time from 217 to 11 sec.

Please run the unit-test TestDateVec to check validity and speed.

Tested: Matlab 6.5, 7.7, 7.8, WinXP, 32bit.
  Pure Matlab code, so compatibility to MacOS, Linux, 64 bit is expected.
  English month names are needed.

Suggestions and question by email or in the comment section are very welcome.

See also: DateStr2Num (Jan Simon)
  http://www.mathworks.com/matlabcentral/fileexchange/28093

Acknowledgements
This submission has inspired the following:
mdatestr, mdatenum: A simple alternative of datestr and datenum
MATLAB release MATLAB 7.8 (R2009a)
Other requirements Compatible with at least Matlab 6.5 to 2009b
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Please login to add a comment or rating.
Updates
02 Jul 2010

Call to external function "isEqualTol" removed from the test function. No changes in the main function.

Tag Activity for this File
Tag Applied By Date/Time
date Jan Simon 19 Oct 2009 09:30:53
conversion Jan Simon 19 Oct 2009 09:30:53
datenum Jan Simon 19 Oct 2009 09:30:53
datestr Jan Simon 19 Oct 2009 09:30:53
datevec Jan Simon 19 Oct 2009 09:30:53
data import Jan Simon 19 Oct 2009 09:30:53
serial date number Jan Simon 19 Oct 2009 09:30:53
string Jan Simon 19 Oct 2009 09:30:53
date vector Jan Simon 19 Oct 2009 09:30:53
string Giles 14 Dec 2009 19:45:45
serial date number Hayk 11 Jan 2012 01:05:10

Contact us at files@mathworks.com