大家好,又见面了,我是你们的朋友全栈君。
TIMESTAMPDIFF(unit,begin,end);
TIMESTAMPDIFF函数返回begin-end的结果,其中begin和end是DATE或DATETIME表达式。
TIMESTAMPDIFF函数允许其参数具有混合类型,例如,begin是DATE值,end可以是DATETIME值。 如果使用DATE值,则TIMESTAMPDIFF函数将其视为时间部分为“00:00:00”的DATETIME值。
unit参数是确定(end-begin)的结果的单位,表示为整数。 以下是有效单位:
MICROSECOND 微秒 SECOND 秒 MINUTE 分钟 HOUR 小时 DAY 天 WEEK 周 MONTH 月份 QUARTER 季度 YEAR 年份
示例:
select timestampdiff(year, "2019-08-13 19:15:16","2020-08-14 13:47:37") as year
,timestampdiff(QUARTER, "2019-08-13 19:15:16","2020-08-14 13:47:37") as QUARTER
,timestampdiff(MONTH, "2020-07-14 13:47:37","2020-08-14 13:47:37") as MONTH
,timestampdiff(WEEK , "2020-08-07 13:47:37","2020-08-14 13:47:37") as WEEK
,timestampdiff(DAY, "2020-08-13 13:47:37","2020-08-14 13:47:37") as DAY
,timestampdiff(HOUR, "2020-08-14 12:47:37","2020-08-14 13:47:37") as HOUR
,timestampdiff(MINUTE , "2020-08-14 12:47:37","2020-08-14 13:47:37") as MINUTE
,timestampdiff(SECOND , "2020-08-14 13:46:37","2020-08-14 13:47:37") as SECOND
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/138911.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...