简体   繁体   中英

subtract a datetime from a timestamp with mysql

I have to do a subtraction between two fields from two different tables, one of the field is a Datetime the other field is a Timestamp.

What's the best way to achieve that ?

convert first to unix timestamp ?

something like:

select UNIX_TIMESTAMP(t1.col1) - UNIX_TIMESTAMP(t2.col2) from t1, t2 ...

TIMESTAMPDIFF is by far the most versatile alternative.

select timestampdiff(SECOND, t1.col1, t2.col2);

See it in fiddle

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