pyspark.sql.functions.make_ym_interval

pyspark.sql.functions.make_ym_interval(years: Optional[ColumnOrName] = None, months: Optional[ColumnOrName] = None) → pyspark.sql.column.Column[source]

Make year-month interval from years, months.

New in version 3.5.0.

Parameters
yearsColumn or str

the number of years, positive or negative

monthsColumn or str

the number of months, positive or negative

Examples

>>> spark.conf.set("spark.sql.session.timeZone", "America/Los_Angeles")
>>> df = spark.createDataFrame([[2014, 12]], ["year", "month"])
>>> df.select(make_ym_interval(df.year, df.month).alias('r')).show(truncate=False)
+-------------------------------+
|r                              |
+-------------------------------+
|INTERVAL '2015-0' YEAR TO MONTH|
+-------------------------------+
>>> spark.conf.unset("spark.sql.session.timeZone")