TIMESTAMPDIFF function in MySQL

The TIMESTAMPDIFF function is a MySQL date/time function used to calculate the difference between two dates/times. Its syntax is as follows:

TIMESTAMPDIFF(unit, datetime1, datetime2)

Among them, the unit parameter is a string indicating the unit of the calculation result. Can be one of the following values:

  • YEAR - year
  • QUARTER - quarter
  • MONTH - month
  • WEEK - week
  • DAY - days
  • HOUR - hours
  • MINUTE - minutes
  • SECOND—Seconds
  • MICROSECOND - microseconds

The datetime1 and datetime2 parameters are date/time expressions, which can be date, time, or datetime types, or literal values ​​or variables of these types.

The TIMESTAMPDIFF function will return the difference between datetime2 minus datetime1, in the units specified by unit. For example, if unit is MONTH, the function will return the difference in months between datetime2 and datetime1.

Guess you like

Origin blog.csdn.net/weixin_65837469/article/details/131049385