Skip to content

Date and time

add_months

add_months(start: Date, months: Integer | int) -> Date

Returns the date months months after start.

Wrapper for pyspark.sql.functions.add_months.

date_add

date_add(start: Date, days: Int) -> Date

Returns the date days days after start.

Wrapper for pyspark.sql.functions.date_add.

date_diff

date_diff(
    end: DateOrTimestamp, start: DateOrTimestamp
) -> Int

Returns the number of days from start to end.

Wrapper for pyspark.sql.functions.date_diff.

date_format

date_format(col: DateOrTimestamp, format: str) -> String

Formats col as a string using the given datetime format pattern.

Wrapper for pyspark.sql.functions.date_format.

date_from_unix_date

date_from_unix_date(days: Integer) -> Date

Converts a number of days since 1970-01-01 to a date.

Wrapper for pyspark.sql.functions.date_from_unix_date.

date_sub

date_sub(start: Date, days: Integer | int) -> Date

Returns the date days days before start.

Wrapper for pyspark.sql.functions.date_sub.

date_trunc

date_trunc(
    format: DateTruncFormat, timestamp: Timestamp
) -> Timestamp

Truncates timestamp to the granularity specified by format (e.g. 'YEAR', 'MONTH', 'DAY').

Wrapper for pyspark.sql.functions.date_trunc.

datediff

datediff(end: Date, start: Date) -> Int

Returns the number of days from start to end.

Wrapper for pyspark.sql.functions.datediff.

day

day(col: DateOrTimestamp) -> Int

Returns the day of the month from col.

Wrapper for pyspark.sql.functions.day.

dayofmonth

dayofmonth(col: DateOrTimestamp) -> Int

Returns the day of the month from col.

Wrapper for pyspark.sql.functions.dayofmonth.

dayofweek

dayofweek(col: DateOrTimestamp) -> Int

Returns the day of the week from col (1 = Sunday, 7 = Saturday).

Wrapper for pyspark.sql.functions.dayofweek.

dayofyear

dayofyear(col: DateOrTimestamp) -> Int

Returns the day of the year from col (1-366).

Wrapper for pyspark.sql.functions.dayofyear.

from_unixtime

from_unixtime(
    timestamp: Long | Integer, format: str | None = None
) -> String

Converts a Unix epoch timestamp (seconds since 1970-01-01) to a formatted string.

Wrapper for pyspark.sql.functions.from_unixtime.

from_utc_timestamp

from_utc_timestamp(
    timestamp: Timestamp, tz: str | String
) -> Timestamp

Interprets timestamp as UTC and converts it to the given timezone tz.

Wrapper for pyspark.sql.functions.from_utc_timestamp.

hour

hour(col: AnyTimestamp) -> Int

Returns the hour component of col (0-23).

Wrapper for pyspark.sql.functions.hour.

last_day

last_day(date: Date) -> Date

Returns the last day of the month that date belongs to.

Wrapper for pyspark.sql.functions.last_day.

make_date

make_date(
    year: Integer | int,
    month: Integer | int,
    day: Integer | int,
) -> Date

Creates a date from year, month, and day components.

Wrapper for pyspark.sql.functions.make_date.

minute

minute(col: AnyTimestamp) -> Int

Returns the minute component of col (0-59).

Wrapper for pyspark.sql.functions.minute.

month

month(col: DateOrTimestamp) -> Int

Returns the month component of col (1-12).

Wrapper for pyspark.sql.functions.month.

months_between

months_between(
    date1: DateOrTimestamp,
    date2: DateOrTimestamp,
    roundOff: bool = True,
) -> Double

Returns the number of months between date1 and date2. Rounds to 8 decimal places when roundOff is True.

Wrapper for pyspark.sql.functions.months_between.

next_day

next_day(date: Date, dayOfWeek: DayOfWeek) -> Date

Returns the first date after date that falls on dayOfWeek (e.g. 'MON', 'MONDAY').

Wrapper for pyspark.sql.functions.next_day.

now

now() -> Timestamp

Returns the current timestamp at query start time.

Wrapper for pyspark.sql.functions.now.

quarter

quarter(col: DateOrTimestamp) -> Int

Returns the quarter of the year from col (1-4).

Wrapper for pyspark.sql.functions.quarter.

second

second(col: AnyTimestamp) -> Int

Returns the second component of col (0-59).

Wrapper for pyspark.sql.functions.second.

timestamp_add

timestamp_add(
    unit: TimestampAddUnit, quantity: Integer, ts: T
) -> T

Adds quantity units to ts. unit is a string such as 'YEAR', 'MONTH', 'DAY', 'HOUR', etc.

Wrapper for pyspark.sql.functions.timestamp_add. Requires Spark 4.0+.

timestamp_diff

timestamp_diff(
    unit: TimeUnit, start: AnyTimestamp, end: AnyTimestamp
) -> Int

Returns the difference between end and start expressed in the given unit.

Wrapper for pyspark.sql.functions.timestamp_diff.

timestamp_micros

timestamp_micros(col: Long) -> Timestamp

Converts microseconds since 1970-01-01 00:00:00 UTC to a timestamp.

Wrapper for pyspark.sql.functions.timestamp_micros.

timestamp_millis

timestamp_millis(col: Long) -> Timestamp

Converts milliseconds since 1970-01-01 00:00:00 UTC to a timestamp.

Wrapper for pyspark.sql.functions.timestamp_millis.

timestamp_seconds

timestamp_seconds(col: Long | Double) -> Timestamp

Converts seconds (with optional fractional part) since 1970-01-01 00:00:00 UTC to a timestamp.

Wrapper for pyspark.sql.functions.timestamp_seconds.

to_date

to_date(col: String, format: str | None = None) -> Date

Parses col as a date using the optional format pattern.

Wrapper for pyspark.sql.functions.to_date.

to_timestamp

to_timestamp(
    col: String | Date, format: str | None = None
) -> Timestamp

Parses col as a timestamp using the optional format pattern.

Wrapper for pyspark.sql.functions.to_timestamp.

to_timestamp_ntz

to_timestamp_ntz(
    col: String, format: str | None = None
) -> TimestampNTZ

Parses col as a timestamp without time zone using the optional format pattern.

Wrapper for pyspark.sql.functions.to_timestamp_ntz.

to_utc_timestamp

to_utc_timestamp(
    timestamp: Timestamp, tz: str | String
) -> Timestamp

Interprets timestamp as being in timezone tz and converts it to UTC.

Wrapper for pyspark.sql.functions.to_utc_timestamp.

trunc

trunc(date: Date, format: TruncFormat) -> Date

Truncates date to the unit specified by format (e.g. 'YEAR', 'MONTH').

Wrapper for pyspark.sql.functions.trunc.

unix_date

unix_date(date: Date) -> Int

Returns the number of days since 1970-01-01 for the given date.

Wrapper for pyspark.sql.functions.unix_date.

unix_micros

unix_micros(col: Timestamp) -> Long

Returns the number of microseconds since 1970-01-01 00:00:00 UTC for col.

Wrapper for pyspark.sql.functions.unix_micros.

unix_millis

unix_millis(col: Timestamp) -> Long

Returns the number of milliseconds since 1970-01-01 00:00:00 UTC for col.

Wrapper for pyspark.sql.functions.unix_millis.

unix_seconds

unix_seconds(col: Timestamp) -> Long

Returns the number of seconds since 1970-01-01 00:00:00 UTC for col.

Wrapper for pyspark.sql.functions.unix_seconds.

unix_timestamp

unix_timestamp(
    timestamp: Timestamp | String | None = None,
    format: str | None = None,
) -> Long

Returns the current Unix timestamp in seconds. Parses timestamp with optional format when provided.

Wrapper for pyspark.sql.functions.unix_timestamp.

weekofyear

weekofyear(col: DateOrTimestamp) -> Int

Returns the week of the year from col (1-53).

Wrapper for pyspark.sql.functions.weekofyear.

year

year(col: DateOrTimestamp) -> Int

Returns the year component of col.

Wrapper for pyspark.sql.functions.year.