Skip to main content

DATEDIFF

This function returns the count (as a signed integer value) of the specified datepart boundaries crossed between the specified startdate and enddate.

Syntax​

DATEDIFF ( datepart , startdate , enddate )  

Arguments​

datepart
The units in which DATEDIFF reports the difference between the startdate and enddate.

Note: Valid datepart arguments { year:"yy", quarter:"q", month:"mm", day:"dd", hour:"hh", minute:"mi", second:"s", millisecond:"ms" and "ns" }.

startdate
A value of the Date & Time data type category.

enddate
A value of the Date & Time data type category.

Return Value​

Returns values of INT64 data type.

Remarks​

DATEDIFF may overflow with a precision of minute or higher if the difference between enddate and startdate returns a value that is out of range for INT64.

Examples​

Examples in this section use the example blockchain.

A. Specifying columns for startdate and enddate​

This example calculates the minute difference between the two time values.

SELECT DATEDIFF("mi", TIME("11:00:00"), TIME("12:00:00"));

Response:

DATEDIFF("mi", TIME("11:00:00"), TIME("12:00:00")) [INT64]
60