Skip to main content

MINUTES_DIFF

Description​

Calculates the minute difference between two datetime values. The result is the number of minutes from <start_date> subtracted from <end_date>.

Syntax​

MINUTES_DIFF(<enddate>, <startdate>)

Parameters​

ParameterDescription
<end_date>The end time, which can be of type DATE, DATETIME, or DATETIMEV2
<start_date>The start time, which can be of type DATE, DATETIME, or DATETIMEV2

Return Value​

Returns an INT type representing the minute difference between the two times.

  • Returns a positive number if <end_date> is greater than <start_date>.
  • Returns a negative number if <end_date> is less than <start_date>.

Example​

SELECT MINUTES_DIFF('2020-12-25 22:00:00', '2020-12-25 21:00:00');
+----------------------------------------------------------------------------------------------------------+
| minutes_diff(cast('2020-12-25 22:00:00' as DATETIMEV2(0)), cast('2020-12-25 21:00:00' as DATETIMEV2(0))) |
+----------------------------------------------------------------------------------------------------------+
| 60 |
+----------------------------------------------------------------------------------------------------------+

Note:

  • The calculation only considers complete minutes; seconds and milliseconds are ignored.
  • If either input parameter is NULL, the function returns NULL.
  • It can handle time differences that span days, months, or years.