Skip to main content

MICROSECONDS_DIFF

Description​

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

Syntax​

MICROSECONDS_DIFF(<enddate>, <startdate>)

Parameters​

ParameterDescription
<end_date>The end time, of type DATETIMEV2
<start_date>The start time, of type DATETIMEV2

Return Value​

Returns an INT type representing the microsecond 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>.
  • 1 second = 1,000,000 microseconds.

Example​

SELECT MICROSECONDS_DIFF('2020-12-25 21:00:00.623000', '2020-12-25 21:00:00.123000');
+-----------------------------------------------------------------------------------------------------------------------------+
| microseconds_diff(cast('2020-12-25 21:00:00.623000' as DATETIMEV2(3)), cast('2020-12-25 21:00:00.123000' as DATETIMEV2(3))) |
+-----------------------------------------------------------------------------------------------------------------------------+
| 500000 |
+-----------------------------------------------------------------------------------------------------------------------------+