Advances a serial date by a number of \a Months. <span align="right" style="background-color:99FF99"><strong>Excel: EDATE</strong></span>

View versions (1)

Interface

#include <codecogs/units/date/incmonth.h>

using namespace Units::Date;

Returns the serial Julian date which equals nDate plus or minus the the specified number of months.

The month is modified using: Month_{new} = Month_{old} + Months. In circumstances where the new date has too many days for the month, the number of days are reduced to accommodate the month. For example: edate("30/March/2004", -1) is 29 February 2004.

Example 1

#include <stdio.h>
#include <codecogs/units/date/incmonth.h>
#include <codecogs/units/date/date.h> 
#include <codecogs/units/date/dateymd.h> 
using namespace Units::Date;

int main()
{
  for(int i=-12; i<=12; i++)
  {
    int d,m,y;
    dateYMD(incMonth(date("31,dec,2004"), i), y, m, d);
    printf("\n incMonth(date(\"31,dec,2004\"),%d)= %2d-%2d-%d",i, d, m, y);
  }
  return 0;
}

Output

19 February 2003 + -4 months is: 19-10-2002
19 February 2003 + -3 months is: 19-11-2002
19 February 2003 + -2 months is: 19-12-2002
19 February 2003 + -1 months is: 19-1-2003
19 February 2003 + 0 months is: 19-2-2003
19 February 2003 + 1 months is: 19-3-2003
19 February 2003 + 2 months is: 19-4-2003
19 February 2003 + 3 months is: 19-5-2003
19 February 2003 + 4 months is: 19-6-2003

Parameters

nDate
is the number of days from 24 November 4714 BC - otherwise known as the Julian Period (also 1 January 4713BC in the Julian Calendar).
months
are the number of months to add (a positive value) or subtract (a negative value) from nDate.
dateSystem
selects which date system should be used (see constants).
GPL Licence — free for non commercial use. See Licence details.