Home > atmlab > time > daysinmonth.m

daysinmonth

PURPOSE ^

DAYSINMONTH Number of days in a month.

SYNOPSIS ^

function dim = daysinmonth(varargin)

DESCRIPTION ^

DAYSINMONTH Number of days in a month.

   DAYSINMONTH(YEAR, MONTH) returns the number of days in the given month.

   If no date is specified, the current date is used.  Gregorian calendar
   is assumed.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

daysinmonth.m

SOURCE CODE ^

0001 function dim = daysinmonth(varargin)
0002 %DAYSINMONTH Number of days in a month.
0003 %
0004 %   DAYSINMONTH(YEAR, MONTH) returns the number of days in the given month.
0005 %
0006 %   If no date is specified, the current date is used.  Gregorian calendar
0007 %   is assumed.
0008 
0009 %   Author:      Peter J. Acklam
0010 %   Time-stamp:  2002-03-03 12:52:00 +0100
0011 %   E-mail:      pjacklam@online.no
0012 %   URL:         http://home.online.no/~pjacklam
0013 
0014    nargsin = nargin;
0015    error(nargchk(0, 2, nargsin));
0016    if nargsin
0017       argv = {1 1};
0018       argv(1:nargsin) = varargin;
0019    else
0020       argv = clock;
0021       argv = num2cell(argv(1:2));
0022    end
0023    [year, month] = deal(argv{:});
0024 
0025    % Now get the number of days in the month.
0026    days = [31 28 31 30 31 30 31 31 30 31 30 31];
0027    dim  = days(month);
0028 
0029    % Add leap day as necessary.
0030    dim = dim + ( month == 2 & isleapyear(year) );

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