简体   繁体   中英

In MYSQL how can I subtract a time field from a datetime field?

In MYSQL I have two fields.

TIME field called status_age. Format is HH:MM:SS DATE TIME called create_date. Format is YYYY-MM-DD HH:MM:SS

I want to ensure that when I subtract the TIME field from the DATETIME field that is will roll back to the previous day if necessary. I've tried timediff and date time diff but the formatting is incorrect.

Any recommendations?

Thanks

将时间转换为秒,然后减去:

SELECT DATE_SUB(`create_date`,INTERVAL  TIME_TO_SEC(`status_age`) SECOND)

您是否尝试过使用date_sub()将时间转换为秒?

select date_sub(create_date, interval time_to_sec(status_age) second)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM