返回顶部

收藏

mysql TIMESTAMPDIFF返回连个日期之间相差的月份,天数秒数等

更多

mysql的TIMESTAMPDIFF函数可以返回两个日期之间的时间差。 如下语法:

TIMESTAMPDIFF(unit,datetime_expr1,datetime_expr2);

参数:

  • unit 返回时间差的单位
  • datetime_expr1 日期
  • datetime_expr2 日期

时间单位如下:

  • MICROSECOND MICROSECONDS
  • SECOND SECONDS
  • MINUTE MINUTES
  • HOUR HOURS
  • DAY DAYS
  • WEEK WEEKS
  • MONTH MONTHS
  • QUARTER QUARTERS
  • YEAR YEARS
  • SECOND_MICROSECOND 'SECONDS.MICROSECONDS'
  • MINUTE_MICROSECOND 'MINUTES:SECONDS.MICROSECONDS'
  • MINUTE_SECOND 'MINUTES:SECONDS'
  • HOUR_MICROSECOND 'HOURS:MINUTES:SECONDS.MICROSECONDS'
  • HOUR_SECOND 'HOURS:MINUTES:SECONDS'
  • HOUR_MINUTE 'HOURS:MINUTES'
  • DAY_MICROSECOND 'DAYS HOURS:MINUTES:SECONDS.MICROSECONDS'
  • DAY_SECOND 'DAYS HOURS:MINUTES:SECONDS'
  • DAY_MINUTE 'DAYS HOURS:MINUTES'
  • DAY_HOUR 'DAYS HOURS'
  • YEAR_MONTH 'YEARS-MONTHS'

例如:

SELECT TIMESTAMPDIFF(SECOND,'2007-12-30 12:01:01','2007-12-31 10:02:00'); 
-- result: 79259  the difference in seconds with the time.

标签:mysql,date

收藏

0人收藏

支持

0

反对

0

发表评论