SQL Function Reference

TIMESTAMPDIFF
Returns the difference between two DATE or DATETIME in a specific unit of measurement
MySQL
TIMESTAMPDIFF(unit, datetime1, datetime2)
unit
The unit of measurement in which to return the difference between the values.
datetime1
The value to be subtracted from datetime2
datetime2
The value from which datetime1 will be subtracted
Unit typeDescription
MICROSECONDMicroseconds
SECONDSeconds
MINUTEMinutes
HOURHours
DAYDays
WEEKWeeks
MONTHMonths
QUARTERQuarter
YEARYears
Examples
MySQL
SELECT TIMESTAMPDIFF(YEAR,'2012-06-12','2022-12-05');
MySQL
SELECT TIMESTAMPDIFF(DAY,'2022-06-12','2022-12-05');