EOMONTH( ) function

Returns the date of the last day of the month that is a specified number of months before or after a specified date.

Syntax

EOMONTH(<date/datetime> <,months>)

Parameters

Name Type Description
date/datetime

optional

datetime

The field, expression, or literal value from which to calculate the end-of-month date. If omitted, the end-of-month date is calculated from the current operating system date.

Note

You can specify a datetime value for date/datetime but the time portion of the value is ignored.

months

optional

numeric

The number of months before or after date/datetime. If omitted, the default of 0 (zero) is used.

You cannot specify months if you have omitted date/datetime.

Output

Datetime. The date value is output using the current Analytics date display format.

Examples

Basic examples

No input

Returns the last day of the month for the current operating system date:

EOMONTH()

Literal input values

The last day of the month

Returns `20140131` displayed as 31 Jan 2014 assuming a current Analytics date display format of DD MMM YYYY:

EOMONTH(`20140115`)

The last day of the month three months in the future

Returns `20140430` displayed as 30 Apr 2014 assuming a current Analytics date display format of DD MMM YYYY:

EOMONTH(`20140115`, 3)

The last day of the month three months in the past

Returns `20131031` displayed as 31 Oct 2013 assuming a current Analytics date display format of DD MMM YYYY:

EOMONTH(`20140115`, -3)

Field input values

The last day of the month three months in the future

Returns the last day of the month that falls three months after each date in the Invoice_date field:

EOMONTH(Invoice_date, 3)

The last day of the month three or four months in the future, depending on the grace period

Returns the last day of the month that falls three or four months after each date in the Invoice_date field. If the addition of the 15-day grace period causes the invoice date to go over a month boundary, then the result is extended an additional month:

EOMONTH(Invoice_date + 15, 3)

Advanced examples

Returning the first day of the following month

Add 1 day to the result of the EOMONTH( ) function to return the date of the first day of the following month.

Returns `20140501` displayed as 01 May 2014 assuming a current Analytics date display format of DD MMM YYYY:

EOMONTH(`20140115`, 3) + 1

Returning the first day of the current month

Returns the first day of the month in which the invoice date falls:

EOMONTH(Invoice_date, -1) + 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:

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 last day of the month in which the date/datetime occurs

Related functions

Use the GOMONTH( ) function if you want to return the exact date, rather than the date of the last day of the month, that is the specified number of months before or after a specified date.