GOMONTH( ) function
Returns the date that is the specified number of months before or after a specified date.
Syntax
GOMONTH(date/datetime, months)
Parameters
Name | Type | Description |
---|---|---|
date/datetime |
datetime |
The field, expression, or literal value from which to calculate the output date. |
months |
numeric |
The number of months before or after date/datetime. Note You can specify a datetime value for date/datetime but the time portion of the value is ignored. |
Output
Datetime. The date value is output using the current Analytics date display format.
Examples
Basic examples
Literal input values
Returns `20140415` displayed as 15 Apr 2014 assuming a current Analytics date display format of DD MMM YYYY:
GOMONTH(`20140115`, 3)
Returns `20131015` displayed as 15 Oct 2013 assuming a current Analytics date display format of DD MMM YYYY:
GOMONTH(`20140115`, -3)
Returns `20140430` displayed as 30 Apr 2014 assuming a current Analytics date display format of DD MMM YYYY (date rounding prevents returning 31 Apr 2014, which is an invalid date):
GOMONTH(`20140330`, 1)
GOMONTH(`20140331`, 1)
Returns `20140501` displayed as 01 May 2014 assuming a current Analytics date display format of DD MMM YYYY:
GOMONTH(`20140401`, 1)
Field input values
Returns the date three months after each date in the Invoice_date field:
GOMONTH(Invoice_date, 3)
Returns the date three months after each date in the Invoice_date field plus a grace period of 15 days:
GOMONTH(Invoice_date + 15, 3)
Remarks
Datetime formats
A field specified for date/datetime can use any date or datetime format, as long as the field definition correctly defines the format.
A literal date value must use one of the following formats:
- YYYYMMDD
- YYMMDD
You must enclose literal date values in backquotes. For example: `20141231`
How the months value works
- Positive value the output date is more recent than the specified date/datetime
- Negative value the output date is prior to the specified date/datetime
- Value omitted, or '0' (zero) the output date is the same as the date/datetime
Date rounding to avoid non-existent dates
If the combination of date/datetime and months would produce a non-existent date, the GOMONTH( ) function uses 'date rounding' to return the closest valid date within the same month.
Returns `20140430` (30 Apr 2014) because 31 Apr 2014 is an invalid date:
GOMONTH(`20140331`,1)
Related functions
Use the EOMONTH( ) function if you want to return the date of the last day of the month, rather than the exact date, that is the specified number of months before or after a specified date.