FUNCTION
endOfMonth
Advances a serial date to the last day of the month after adding \a months. <span align="right" style="background-color:99FF99"><strong>Excel: EOMONTH</strong></span>
Interface
#include <codecogs/units/date/endofmonth.h>
using namespace Units::Date;
Returns the serial Julian date which equals the last day of the month for nDate plus or minus the offset provided by months.
The month is modified using: . The day part of nDate is always overwritten with the maximum number of days in the new month.
Example 1
#include <stdio.h>
#include <codecogs/units/date/endofmonth.h>
#include <codecogs/units/date/date.h>
using namespace Units::Date;
int main()
{
for(int i=-2; i<=2; i++)
{
int d,m,y;
dateYMD(endOfMonth(date("19,feb,2003"), i), y, m, d);
printf("\n Month end for 19 February 2003 + %d months is: %d-%d-%d",i, d, m, y);
}
for(int i=-2; i<=2; i++)
{
int d,m,y;
dateYMD(endOfMonth(date("31,dec,2004"), i), y, m, d);
printf("\n Month end for 31 December 2004 + %d months is: %d-%d-%d",i, d, m, y);
}
return 0;
}Output:
Month end for 19 February 2003 + -2 months is: 31-12-2002
Month end for 19 February 2003 + -1 months is: 31-1-2003
Month end for 19 February 2003 + 0 months is: 28-2-2003
Month end for 19 February 2003 + 1 months is: 31-3-2003
Month end for 19 February 2003 + 2 months is: 30-4-2003
Month end for 31 December 2004 + -2 months is: 31-10-2004
Month end for 31 December 2004 + -1 months is: 30-11-2004
Month end for 31 December 2004 + 0 months is: 31-12-2004
Month end for 31 December 2004 + 1 months is: 31-1-2005
Month end for 31 December 2004 + 2 months is: 28-2-2005Parameters
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):
Blank
- cal_Gregorian (default)
- cal_Julian
- cal_Excel (same as Gregorian)
This function's source code is only visible to registered users — documentation and the calculator above are free to use either way. Sign in to see it.