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

View versions (2)

Interface

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

using namespace Units::Date;

Returns the serial Julian date which equals nDate plus or minus 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:

incMonth(date("31,dec,2004"),-12)= 31-12-2003
 incMonth(date("31,dec,2004"),-11)= 31- 1-2004
 incMonth(date("31,dec,2004"),-10)= 29- 2-2004
 incMonth(date("31,dec,2004"),-9)= 31- 3-2004
 incMonth(date("31,dec,2004"),-8)= 30- 4-2004
 incMonth(date("31,dec,2004"),-7)= 31- 5-2004
 incMonth(date("31,dec,2004"),-6)= 30- 6-2004
 incMonth(date("31,dec,2004"),-5)= 31- 7-2004
 incMonth(date("31,dec,2004"),-4)= 31- 8-2004
 incMonth(date("31,dec,2004"),-3)= 30- 9-2004
 incMonth(date("31,dec,2004"),-2)= 31-10-2004
 incMonth(date("31,dec,2004"),-1)= 30-11-2004
 incMonth(date("31,dec,2004"),0)= 31-12-2004
 incMonth(date("31,dec,2004"),1)= 31- 1-2005
 incMonth(date("31,dec,2004"),2)= 28- 2-2005
 incMonth(date("31,dec,2004"),3)= 31- 3-2005
 incMonth(date("31,dec,2004"),4)= 30- 4-2005
 incMonth(date("31,dec,2004"),5)= 31- 5-2005
 incMonth(date("31,dec,2004"),6)= 30- 6-2005
 incMonth(date("31,dec,2004"),7)= 31- 7-2005
 incMonth(date("31,dec,2004"),8)= 31- 8-2005
 incMonth(date("31,dec,2004"),9)= 30- 9-2005
 incMonth(date("31,dec,2004"),10)= 31-10-2005
 incMonth(date("31,dec,2004"),11)= 30-11-2005
 incMonth(date("31,dec,2004"),12)= 31-12-2005

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.