MySQL中两个DateTime字段相减

假定表名为tblName,两个DateTime字段名分别为beginDateTime,endDateTime,以下是相关两个mysql日期字段相减的SQL语句,这种方式两字段跨天,月,年都无问题。

 

得到两个日期字段之间的秒数

selec t (UNIX_TIMESTAMP(endDateTime) - UNIX_TIMESTAMP(beginDateTime)) dif_second from tblName

 

得到两个日期字段之间的分数

selec t (UNIX_TIMESTAMP(endDateTime) - UNIX_TIMESTAMP(beginDateTime))/60 dif_minute from tblName

 

得到两个日期字段之间的天数

selec t (UNIX_TIMESTAMP(endDateTime) - UNIX_TIMESTAMP(beginDateTime))/(60*60*24) dif_minute from tblName

 

出处:https://blog.csdn.net/cqrf2006/article/details/42080559

 

相关文章:

  • 2022-01-14
  • 2021-11-03
  • 2022-12-23
  • 2022-12-23
  • 2021-10-29
  • 2022-12-23
  • 2021-12-03
猜你喜欢
  • 2021-11-22
  • 2021-12-03
  • 2022-12-23
  • 2021-06-20
  • 2021-04-17
  • 2021-12-03
  • 2022-12-23
相关资源
相似解决方案