The monthmath( function takes a date and computes the date that is one or more months before or after the original date.


This function has two parameters:

date – is a number representing the original date.

offset – is the number of months to add or subtract from the date.


This function offsets a date by a number of months. For example, if you offset the date May 12, 1997 by two months the result is July 12, 1997. If you offset the same original date by minus two months the result is March 12, 1997.

If the new date does not exist because a month does not have enough days in it, the monthmath( function will pick the last day of the month. For example, if you offset March 31 by 1 month the result is April 30. If the new month lands in February the function knows about leap years and adjusts accordingly.

datepattern(monthmath(date("mar 31, 2012"),1),"Month ddnth, YYYY") ☞ April 30th, 2012
datepattern(monthmath(date("mar 31, 2012"),-1),"Month ddnth, YYYY") ☞ February 29th, 2012
datepattern(monthmath(date("mar 31, 2012"),2),"Month ddnth, YYYY") ☞ May 31st, 2012
datepattern(monthmath(date("mar 31, 2012"),12),"Month ddnth, YYYY") ☞ March 31st, 2013

Note: These examples assume the system’s Date & Time preferences are set to US format. If a non-US format is being used, the date values would have to be adjusted.

See Also


10.0No ChangeCarried over from Panorama 6.0