I have two columns(date_start
and date_due
) which contain dates values.
我有两列(date_start和date_due),其中包含日期值。
Is it possible to get their difference(in hours) and set it in another column(duration_hours
) using single UPDATE query
?
是否可以使用单个UPDATE查询获取它们的差异(以小时为单位)并将其设置在另一列(duration_hours)中?
1 个解决方案
#1
4
you can use TIMESTAMPDIFF
function.
你可以使用TIMESTAMPDIFF函数。
UPDATE mytable SET duration_hours = TIMESTAMPDIFF(HOUR, date_start, date_due) where date_start is not null OR date_due is not null or date_start !='' OR date_due !=''
source: https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_timestampdiff
#1
4
you can use TIMESTAMPDIFF
function.
你可以使用TIMESTAMPDIFF函数。
UPDATE mytable SET duration_hours = TIMESTAMPDIFF(HOUR, date_start, date_due) where date_start is not null OR date_due is not null or date_start !='' OR date_due !=''
source: https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_timestampdiff