GOMONTH( ) function
Returns the date that is a 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
Add three months
Returns `20140415` displayed as 15 Apr 2014 assuming a current Analytics date display format of DD MMM YYYY:
GOMONTH(`20140115`, 3)
Subtract three months
Returns `20131015` displayed as 15 Oct 2013 assuming a current Analytics date display format of DD MMM YYYY:
GOMONTH(`20140115`, -3)
Field input values
Add three months
Returns the date three months after each date in the Invoice_date field:
GOMONTH(Invoice_date, 3)
Add three months and fifteen days
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)
Advanced examples
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 previous date.
No date rounding required
Adding one month to 30 March 2014 returns `20140430`, displayed as 30 Apr 2014 assuming a current Analytics date display format of DD MMM YYYY:
GOMONTH(`20140330`, 1)
Date rounding applied
Adding one month to 31 March 2014 also returns `20140430`, displayed as 30 Apr 2014 assuming a current Analytics date display format of DD MMM YYYY. Date rounding prevents the second example returning 31 Apr 2014, which is an invalid date.
GOMONTH(`20140331`, 1)
Remarks
Date and time functions can sometimes be challenging to use correctly. In the Help, function topics describe the specific details of how each function works. For information about some general considerations when using date and time functions, see the following topics:
- Using datetimes in expressions
- Serial datetimes
- How UTC offsets affect datetime expressions
- Date and Time options
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
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.