GoMonth()
This function returns a date offset from the date or datetime supplied by the number of months indicated (positive or negative). It is limited to dates in the year 1753 or later, returning empty dates if that lower limit is exceeded. Watch out for the type change this function causes: GOMONTH() always returns a date, whether supplied with a date or a datetime.
Usage |
dReturn = GOMONTH( dDate | tDateTime, nOffset ) |
* DiffDate.PRG * Returns the absolute difference in number of days between 2 dates, * ignoring year, i.e., 9/8/43 vs. 9/9/94 returns 1 and * 7/6/12 vs. 7/5/83 returns 1. LPARAMETERS tdDate1, tdDate2 LOCAL ldNewDate, lnDifference, lnYears * Validate parameters, force to today's date if blank tdDate1 = MakeItDate(tdDate1) tdDate2 = MakeItDate(tdDate2) * Use GOMONTH() function to bring dates into the same year, then * subtract the difference. lnYears = YEAR(tdDate2) - YEAR(tdDate1) ldNewDate = GOMONTH(tdDate1, lnYears * 12) lnDifference = tdDate2 – ldNewDate * If they're still too far apart, bump ldNewDate a year + / - IF ABS(lnDifference) > 182 lnYears = lnYears + 1*SIGN(lnDifference) ldNewDate = GOMONTH(tdDate1, lnYears * 12) lnDifference = tdDate2 – ldNewDate ENDIF RETURN ABS(lnDifference) FUNCTION MakeItDate (tdDate2Test) * Validate the parameter as a legitimate date or * default to today's date instead. RETURN IIF(EMPTY(tdDate2Test) OR ; NOT INLIST(TYPE("tdDate2Test"),"D","T"), ; DATE(), ; tdDate2Test)
Example |
? GOMONTH({06/15/1958},70*12) && Returns "06/15/2028" * A favorite of Doug, to calculate the * last day of the current month. ldLastDay = GOMONTH(DATE() - DAY(DATE()) + 1, 1) – 1 |
See Also |
CDoW(), CMonth(), Date(), Day(), DMY(), DoW(), MDY(), Month(), Set Century, Set Date, Set Mark To, Year() |