gpt4 book ai didi

时间戳中的mysql时间戳差异

转载 作者:可可西里 更新时间:2023-11-01 07:57:03 26 4
gpt4 key购买 nike

我想了解时间戳之间的区别,以时间戳格式,仅使用 MySQL 而不是使用编程语言。也不以秒、小时、日期、月或年为单位。举个例子。

timestamp1->2012-05-21 15:31:11
timestamp2->2012-05-21 15:32:11

我想得到时间戳格式的结果。

所以结果应该是

result->0000-00-00 00:01:00

最佳答案

使用 MySQL 的 TIMEDIFF()功能:

TIMEDIFF() returns expr1expr2 expressed as a time value. expr1 and expr2 are time or date-and-time expressions, but both must be of the same type.

The result returned by TIMEDIFF() is limited to the range allowed for TIME values. Alternatively, you can use either of the functions TIMESTAMPDIFF() and UNIX_TIMESTAMP(), both of which return integers.

mysql> SELECT TIMEDIFF('2000:01:01 00:00:00',    ->                 '2000:01:01 00:00:00.000001');        -> '-00:00:00.000001'mysql> SELECT TIMEDIFF('2008-12-31 23:59:59.000001',    ->                 '2008-12-30 01:01:01.000002');        -> '46:58:57.999999'

关于时间戳中的mysql时间戳差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10797363/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com