Subtract timestamp/date

Supported in: Batch, Streaming

Returns the difference in the given time unit.

Expression categories: Datetime

Declared arguments

  • End - The end date or time to subtract from.
    Expression<Date | Timestamp>
  • Start - The start date or time to be subtracted.
    Expression<Date | Timestamp>
  • Unit - Time unit.
    Enum<Days, Hours, Milliseconds, Minutes, Months, Quarters, Seconds, Weeks, Years>

Output type: Long

Examples

Example 1: Base case

Argument values:

  • End: 2022-10-01T10:00:00Z
  • Start: 2022-10-01T09:00:00Z
  • Unit: HOURS

Output: 1


Example 2: Null case

Argument values:

  • End: End
  • Start: Start
  • Unit: HOURS
StartEndOutput
null2020-01-01null
2020-01-01nullnull
nullnullnull