Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
266 views
in Technique[技术] by (71.8m points)

mysql - MySQL中DateTime操作的结果是什么(What is the result of DateTime operation in MySQL)

I tried the following SQL query.

(我尝试了以下SQL查询。)

select start_time, end_time, end_time-start_time from orders

This printed the following output.

(这打印了以下输出。)

start_time          |end_time             |end_time-start_time
...
2019-11-29 15:55:54 | 2019-12-01 15:59:00 | 72000346
...

I have no idea what the result means.

(我不知道结果意味着什么。)

I know that we can use TIMESTAMPDIFF to calculate difference between two datetime.

(我知道我们可以使用TIMESTAMPDIFF来计算两个日期时间之间的差异。)

Does anyone know what the result means?

(有人知道结果意味着什么吗?)

  ask by Ma Long translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
select 
  start_time,
  end_time, 
  '0000000000000000000'+end_time   as exp1,
  '0000000000000000000'-start_time as exp2,
  '0000000000000000000'+end_time - '0000000000000000000'-start_time      as exp3
from orders;

output:

(输出:)

+---------------------+---------------------+----------------+-----------------+----------+
| start_time          | end_time            | exp1           | exp2            | exp3     |
+---------------------+---------------------+----------------+-----------------+----------+
| 2019-11-29 15:55:54 | 2019-12-01 15:59:00 | 20191201155900 | -20191129155554 | 72000346 |
+---------------------+---------------------+----------------+-----------------+----------+

What is the internal representation of timestamp values in MySQL

(MySQL中时间戳值的内部表示是什么)

https://dev.mysql.com/doc/refman/5.5/en/date-and-time-literals.html

(https://dev.mysql.com/doc/refman/5.5/zh-CN/date-and-time-literals.html)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...