make_ym_interval function

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime 10.4 LTS and above

Creates an year-month interval from years and months.

Syntax

make_ym_interval( [ years [, months ] ] )

Arguments

  • years: An integral number of years, positive or negative
  • months: An integral number of months, positive or negative

Returns

An INTERVAL YEAR TO MONTH.

Unspecified arguments are defaulted to 0. If you provide no arguments the result is an INTERVAL '0-0' YEAR TO MONTH.

The function is equivalent to executing:

INTERVAL year YEARS + INTERVAL month MONTHS.

As such each unit can be outside of its natural range as well as negative.

Examples

> SELECT make_ym_interval(100, 5);
  100-5

> SELECT make_ym_interval(100, null);
  NULL

> SELECT make_ym_interval(0, 13);
  1-1

> SELECT make_ym_interval(1, -1);
  0-11