Home > atmlab > time > daterange.m

daterange

PURPOSE ^

daterange Returns a matrix of valid dates within the daterange

SYNOPSIS ^

function dates = daterange(date1, date2)

DESCRIPTION ^

 daterange Returns a matrix of valid dates within the daterange

 FORMAT

   dates = daterange(date1, date2)

 IN

   date1   array   Starting date
   date2   array   Ending date

 OUT

   dates   Nxlength(date1) Matrtix  All dates in the range

 NOTE

  If 4th element of date (hour) is given, any missing minute or hour is assumed to be 0

 FORMAT

   dates = daterange(date1, date2)


 $Id: daterange.m 8570 2013-08-10 18:36:48Z seliasson $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

daterange.m

SOURCE CODE ^

0001 function dates = daterange(date1, date2)
0002 
0003 % daterange Returns a matrix of valid dates within the daterange
0004 %
0005 % FORMAT
0006 %
0007 %   dates = daterange(date1, date2)
0008 %
0009 % IN
0010 %
0011 %   date1   array   Starting date
0012 %   date2   array   Ending date
0013 %
0014 % OUT
0015 %
0016 %   dates   Nxlength(date1) Matrtix  All dates in the range
0017 %
0018 % NOTE
0019 %
0020 %  If 4th element of date (hour) is given, any missing minute or hour is assumed to be 0
0021 %
0022 % FORMAT
0023 %
0024 %   dates = daterange(date1, date2)
0025 %
0026 %
0027 % $Id: daterange.m 8570 2013-08-10 18:36:48Z seliasson $
0028 
0029 errId = ['atmlab' mfilename ':badInput'];
0030 assert(length(date1)==length(date2),errId,...
0031     'length(date1)~=length(date2)')
0032 
0033 dl = length(date1);
0034 
0035 if dl ==2
0036     date1(3) = 1;
0037     date2(3) = 1;
0038 end
0039 % datenum wants length(date) ==3 or ==6
0040 if dl > 3
0041     % fill missing with 0
0042     date1(end+1:6) = 0;
0043     date2(end+1:6) = 0;
0044 end
0045 dn1 = datenum(date1);
0046 dn2 = datenum(date2);
0047 
0048 switch dl
0049     case 2
0050         dates = datevec(dn1:dn2);
0051         dates = unique(dates(:, 1:2),'rows'); % only year/month/day part
0052     case 3
0053         dates = datevec(dn1:dn2);
0054         dates = dates(:, 1:3); % only year/month/day part
0055     case 4
0056         dates = datevec(dn1:1/24:dn2); %hour steps
0057         dates = dates(:, 1:4);
0058         
0059     case 5
0060         dates = datevec(dn1:1/(24*60):dn2); %minute steps
0061         dates = dates(:, 1:5);
0062     case 6
0063         dates = datevec(dn1:1/(24*3600):dn2); %seconds steps
0064     
0065     otherwise
0066         error(errId,'datevector lengths=%d is not supported',dl)    
0067 end
0068 
0069 end

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005