Home > atmlab > time > monthofyear.m

monthofyear

PURPOSE ^

MONTHOFYEAR Ordinal number of month in year.

SYNOPSIS ^

function ym = monthofyear( varargin )

DESCRIPTION ^

MONTHOFYEAR Ordinal number of month in year.

   MONTHOFYEAR(YEAR, MONTH, DAY, HOUR, MINUTE, SECOND) returns the ordinal
   month number in the given year plus a fractional part depending on the
   day and time of day.

   Any missing MONTH or DAY will be replaced by ones.  Any missing HOUR,
   MINUTE or SECOND will be replaced by zeros.

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

monthofyear.m

SOURCE CODE ^

0001 function ym = monthofyear( varargin )
0002 %MONTHOFYEAR Ordinal number of month in year.
0003 %
0004 %   MONTHOFYEAR(YEAR, MONTH, DAY, HOUR, MINUTE, SECOND) returns the ordinal
0005 %   month number in the given year plus a fractional part depending on the
0006 %   day and time of day.
0007 %
0008 %   Any missing MONTH or DAY will be replaced by ones.  Any missing HOUR,
0009 %   MINUTE or SECOND will be replaced by zeros.
0010 %
0011 %   If no date is specified, the current date and time is used.  Gregorian
0012 %   calendar is assumed.
0013 
0014 %   Author:      Peter J. Acklam
0015 %   Time-stamp:  2002-03-03 12:50:16 +0100
0016 %   E-mail:      pjacklam@online.no
0017 %   URL:         http://home.online.no/~pjacklam
0018 
0019 % 2006-03-31   Introduced day-1 to reduce a slight "bias". Without -1
0020 %              the month can be 13.
0021 
0022    nargsin = nargin;
0023    error(nargchk(0, 6, nargsin));
0024    if nargsin
0025       argv = {1 1 1 0 0 0};
0026       argv(1:nargsin) = varargin;
0027    else
0028       argv = num2cell(clock);
0029    end
0030    [year, month, day, hour, minute, second] = deal(argv{:});
0031 
0032    ym = month + (dayofmonth(year, month, day-1, hour, minute, second)) ...
0033                 ./ daysinmonth(year, month);

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