datediff.slt 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. mode cockroach
  10. query IIIII
  11. SELECT
  12. datediff('year', '2023-05-08', '2023-06-07'),
  13. datediff('month', '2023-05-08', '2023-06-07'),
  14. datediff('week', '2023-05-08', '2023-06-07'),
  15. datediff('day', '2023-05-08', '2023-06-07'),
  16. datediff('hour', '2023-05-08', '2023-06-07')
  17. ----
  18. 0 1 4 30 720
  19. query IIIIIIII
  20. SELECT
  21. datediff('millennia', '2000-12-31', '2001-01-01'),
  22. datediff('century', '2000-12-31', '2001-01-01'),
  23. datediff('decade', '2000-12-31', '2001-01-01'),
  24. datediff('year', '2000-12-31', '2001-01-01'),
  25. datediff('quarter', '2000-12-31', '2001-01-01'),
  26. datediff('month', '2000-12-31', '2001-01-01'),
  27. datediff('year', '2000-12-31', '2001-01-01'),
  28. datediff('day', '2000-12-31', '2001-01-01')
  29. ----
  30. 1 1 0 1 1 1 1 1
  31. query IIIII
  32. SELECT
  33. datediff('year', '1998-01-01', '2000-06-01'),
  34. datediff('quarter', '1998-01-01', '2000-06-01'),
  35. datediff('month', '1998-01-01', '2000-06-01'),
  36. datediff('week', '1998-01-01', '2000-06-01'),
  37. datediff('day', '1998-01-01', '2000-06-01')
  38. ----
  39. 2 9 29 126 882
  40. query I
  41. SELECT datediff('month', '2023-05-08', '2024-06-08');
  42. ----
  43. 13
  44. query I
  45. SELECT datediff('day', '2023-06-08', '2023-06-07');
  46. ----
  47. -1
  48. # Make sure we correctly handle leap years
  49. query I
  50. SELECT datediff('day', '2004-03-01', '2004-02-28');
  51. ----
  52. -2
  53. query I
  54. SELECT datediff('day', '2005-03-01', '2005-02-28');
  55. ----
  56. -1
  57. query I
  58. SELECT datediff('day', '2005-02-01', '2004-02-01');
  59. ----
  60. -366
  61. query I
  62. SELECT datediff('day', '2004-02-01', '2005-02-01');
  63. ----
  64. 366
  65. query I
  66. SELECT datediff('day', '2005-03-01', '2004-03-01');
  67. ----
  68. -365
  69. query I
  70. SELECT datediff('hour', '2017/08/25 07:00', '2017/08/25 12:45');
  71. ----
  72. 5
  73. query I
  74. SELECT datediff('hour', '2023-01-01', '2023-01-03 05:04:03');
  75. ----
  76. 53
  77. query I
  78. SELECT datediff('days', '2008-06-01 09:59:59 EST', '2008-07-04 09:59:59 EST');
  79. ----
  80. 33
  81. query T
  82. SELECT to_timestamp(-210833720368);
  83. ----
  84. 4713-12-10 21:40:32+00 BC
  85. query T
  86. SELECT to_timestamp(0);
  87. ----
  88. 1970-01-01 00:00:00+00
  89. query T
  90. SELECT to_timestamp(8200000000000);
  91. ----
  92. 261817-08-28 09:46:40+00
  93. query T
  94. SELECT datediff('mil', '0001-01-01', '2000-01-01');
  95. ----
  96. 1
  97. query IIIII
  98. SELECT
  99. datediff('usec', to_timestamp(-210833720368), to_timestamp(8200000000000)),
  100. datediff('ms', to_timestamp(-210833720368), to_timestamp(8200000000000)),
  101. datediff('s', to_timestamp(-210833720368), to_timestamp(8200000000000)),
  102. datediff('m', to_timestamp(-210833720368), to_timestamp(8200000000000)),
  103. datediff('h', to_timestamp(-210833720368), to_timestamp(8200000000000))
  104. ----
  105. 8410833720368000000 8410833720368000 8410833720368 140180562006 2336342700
  106. query IIIIII
  107. SELECT
  108. datediff('days', to_timestamp(-210833720368), to_timestamp(8200000000000)),
  109. datediff('months', to_timestamp(-210833720368), to_timestamp(8200000000000)),
  110. datediff('years', to_timestamp(-210833720368), to_timestamp(8200000000000)),
  111. datediff('decade', to_timestamp(-210833720368), to_timestamp(8200000000000)),
  112. datediff('century', to_timestamp(-210833720368), to_timestamp(8200000000000)),
  113. datediff('millennia', to_timestamp(-210833720368), to_timestamp(8200000000000))
  114. ----
  115. 97347612 3198344 266529 26653 2667 267