DATE_DIFF
Returns the difference between two expressions of time as another expression of time.
Syntax
DATE_DIFF(date_expression DATE, days INTEGER) → DATE
date_expression: The date, in the format ‘YYY-MM-DD’, to subtract days from. The value can be either a database column in DATE format, or literal value explicitly converted to DATE.
days: A 32-bit integer of the number of days to be subtracted from the specified date.
Examples
DATE_DIFF(date_expression DATE, date_expression DATE) → INTERVAL DAY
date_expression: The date, in the format ‘YYY-MM-DD’, to subtract the second date from. The value can be either a database column in DATE format, or literal value explicitly converted to DATE.
date_expression: The date, in the format ‘YYY-MM-DD’, to subtract from the first date. The value can be either a database column in DATE format, or literal value explicitly converted to DATE.
Examples
DATE_DIFF(timestamp_expression TIMESTAMP, timestamp_expression TIMESTAMP) → INTERVAL DAY
timestamp_expression: The timestamp, in the format ‘YYYY-MM-DD HH:MM:SS’, to subtract the second timestamp from. The value can be either a database column in TIMESTAMP format, or literal value explicitly converted to TIMESTAMP.
timestamp_expression: The timestamp, in the format ‘YYYY-MM-DD HH:MM:SS’, to subtract from the first timestamp. The value can be either a database column in TIMESTAMP format, or literal value explicitly converted to TIMESTAMP.
Examples
DATE_DIFF(time_expression TIME, time_interval INTERVAL) → TIME
time_expression: The time, in the format ‘HH:MM:SS’, from which to subtract a number of seconds, minutes, or hours. The value can be either a database column in TIME format, or literal value explicitly converted to TIME.
time_interval: A CAST of a number to one of these intervals: SECOND, MINUTE, HOUR.
Examples
DATE_DIFF(date_expression DATE, time_interval INTERVAL) → TIMESTAMP
date_expression: The date, in the format ‘YYYY-MM-DD’, from which to subtract a number of days, months, or years. The value can be either a database column in DATE format, or literal value explicitly converted to DATE.
time_interval: A CAST of a number to one of these intervals: DAY, MONTH, YEAR.
Examples
DATE_DIFF(timestamp_expression TIMESTAMP, days INTEGER) → TIMESTAMP
timestamp_expression: The timestamp, in the format ‘YYYY-MM-DD HH:MM:SS’, to subtract days from. The value can be either a database column in TIMESTAMP format, or literal value explicitly converted to TIMESTAMP.
days: A 32-bit integer of the number of days to be subtracted from the specified timestamp.
Examples
DATE_DIFF(timestamp_expression TIMESTAMP, time_interval INTERVAL) → TIMESTAMP
timestamp_expression: The timestamp, in the format ‘YYYY-MM-DD HH:MM:SS’, from which to subtract a number of seconds, minutes, hours, days, months, or years. The value can be either a database column in TIMESTAMP format, or literal value explicitly converted to TIMESTAMP.
time_interval: A CAST of a number to one of these intervals: SECOND, MINUTE, HOUR, DAY, MONTH, YEAR.
Examples
Last updated