时间差异产生不同结果

huangapple go评论99阅读模式
英文:

Time difference getting different result

问题

以下是您提供的查询代码的翻译部分:

  1. 我正在使用以下查询:
  2. SELECT
  3. concat(
  4. extract(day from ('2023-02-27 15:09:00'::timestamp - '2022-06-09 15:39:00'::timestamp),' days ',
  5. extract(hour from ('2023-02-27 15:09:00'::timestamp - '2022-06-09 15:39:00'::timestamp),' hours ',
  6. extract(minute from ('2023-02-27 15:09:00'::timestamp - '2022-06-09 15:39:00'::timestamp),' minutes ',
  7. extract(second from ('2023-02-27 15:09:00'::timestamp - '2022-06-09 15:39:00'::timestamp),' seconds'
  8. ) as duration,
  9. justify_interval(make_interval(secs => 22725019)) AS "duration 2"

请注意,这是SQL查询的翻译,不包括结果或问题的回答。如果您需要进一步的帮助,请随时提出。

英文:

I'm using the following query :

  1. SELECT
  2. concat(
  3. extract(day from ('2023-02-27 15:09:00'::timestamp - '2022-06-09 15:39:00'::timestamp)),' days ',
  4. extract(hour from ('2023-02-27 15:09:00'::timestamp - '2022-06-09 15:39:00'::timestamp)),' hours ',
  5. extract(minute from ('2023-02-27 15:09:00'::timestamp - '2022-06-09 15:39:00'::timestamp)),' minutes ',
  6. extract(second from ('2023-02-27 15:09:00'::timestamp - '2022-06-09 15:39:00'::timestamp)),' seconds'
  7. ) as duration,
  8. justify_interval(make_interval(secs =>22725019)) AS "duration 2"

Output :

  1. ----------------------------------------------------------------------------------------------------
  2. | duration | duration 2 |
  3. ----------------------------------------------------------------------------------------------------
  4. | 262 days 23 hours 30 minutes 0.000000 seconds | {"months":8,"days":23,"minutes":30,"seconds":19} |
  5. ----------------------------------------------------------------------------------------------------

On this website I have the following result (https://www.timeanddate.com/date/durationresult.html?d1=09&m1=06&y1=2022&d2=27&m2=02&y2=2023&h1=15&i1=39&s1=00&h2=15&i2=09&s2=00):

  1. 262 days, 23 hours, 30 minutes and 0 seconds
  2. 8 months, 17 days, 23 hours, 30 minutes

Demo : https://www.db-fiddle.com/f/7aYekUESoZwv6DJv77VaCW/0

Why do I have different result ?

EDIT :

22725019 is the result of

  1. ((1677506971778 - 1654781952676) / 1000)

答案1

得分: 2

你可以在差值的结果上使用 justify_interval()

  1. justify_interval('2023-02-27 15:09:00'::timestamp - '2022-06-09 15:39:00'::timestamp)
英文:

You can use justify_interval() on the result of the difference:

  1. justify_interval('2023-02-27 15:09:00'::timestamp - '2022-06-09 15:39:00'::timestamp)

huangapple
  • 本文由 发表于 2023年3月7日 00:26:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/75653343.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定