shiftmonths(X;Y;E)

Returns the date-related value shifted by the number of months specified.

Syntax

shiftmonths(X;Y;E)

Input

Argument Type Description
X
  • integer
  • big integer
A scalar value or the name of a column containing date-related values
Valid values can be of the form:
  • date
Y
  • integer
  • big integer
The amount of months to shift X

If Y > 0, shift forward. If Y < 0, shift backward.

E
  • integer
  • big integer
A value of 0 or 1 that determines how to handle end-of-the-month values of X.
  • If E=0 and X is the last day of the month, the day in the resultant date is the same day of the month as X.
  • If E=1 and X is the last day of the month, the day in the resultant date is the last day of the resultant month.
Note: The day in the resultant date will never be greater than the last day of that month, regardless of the value of E.

For more information, see Dates and time.

Note: Support for columns of type big integer available as of version 11.25.

Return Value

Returns the integer value (in date form) of the date value given as input, shifted by the number of months specified.

If the input values are not in one of the supported formats listed above, the function returns an erroneous or illogical output.

Example

In the Hourly U.S. Weather (1990) table (pub.demo.weather.hourly90), you can create a computed column that displays an integer value corresponding to the date value in the column named date shifted by 1 month:

<base table="pub.demo.weather.hourly90"/>
<willbe name="example" value="shiftmonths(date;1;0)" label="Shift`1 Month"/>
<colord cols="date,example"/>
Because E = 0 in this example:
  • For a date value of 02/27/90 (X=19900227), the result would be 03/27/90.
  • For a date value of 02/28/90 (X=19900228), the result would be 03/28/90. (The same day as the input date.)
  • For a date value of 05/31/90 (X=19900531), the result would be 06/30/90.
If E = 1 in this example:
  • For a date value of 02/27/90 (X=19900227), the result would be 03/27/90.
  • For a date value of 02/28/90 (X=19900228), the result would be 03/31/90. (The last day of the resultant month.)
  • For a date value of 05/31/90 (X=19900531), the result would be 06/30/90.