EndOf.sql 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* syntax version 1 */
  2. $format = DateTime::Format("%Y-%m-%d %H:%M:%S %Z");
  3. select
  4. $format(DateTime::EndOfMonth(TzDateTime('2023-07-07T01:02:03,Europe/Moscow'))),
  5. $format(DateTime::EndOfMonth(Date('2023-08-08'))),
  6. $format(DateTime::EndOfMonth(Date('2023-09-09'))),
  7. $format(DateTime::EndOfMonth(Date('2023-02-02'))),
  8. $format(DateTime::EndOfMonth(Date('2024-02-02')))
  9. into result `Normal cases`;
  10. $tsMin = '1970-01-01T00:00:00.000000';
  11. $tsMax = '2105-12-31T23:59:59.999999';
  12. $tsBelow = '1969-12-31T23:59:59.999999';
  13. $tsAbove = '2106-01-01T00:00:00.000000';
  14. select $format(cast($tsMin || 'Z' as Timestamp))
  15. , $format(DateTime::EndOfMonth(cast($tsMin || 'Z' as Timestamp)))
  16. , $format(DateTime::EndOfMonth(cast($tsMin || ',Atlantic/Madeira' as Timestamp)))
  17. into result `Minimal timestamp value`;
  18. select $format(cast($tsMax || 'Z' as Timestamp))
  19. , $format(DateTime::EndOfMonth(cast($tsMax || 'Z' as Timestamp)))
  20. , $format(DateTime::EndOfMonth(cast('2105-12-12T00:00:00Z' as Timestamp)))
  21. , $format(DateTime::EndOfMonth(cast($tsMax || ',Atlantic/Azores' as Timestamp)))
  22. into result `Maximum timestamp value`;
  23. select $format(cast($tsBelow || ',Atlantic/Azores' as TzTimestamp))
  24. , $format(DateTime::EndOfMonth(cast($tsBelow || ',Atlantic/Azores' as TzTimestamp)))
  25. into result `Timestamp below minimum`;
  26. select $format(cast($tsAbove || ',Atlantic/Madeira' as TzTimestamp))
  27. , $format(DateTime::EndOfMonth(cast($tsAbove || ',Atlantic/Madeira' as TzTimestamp)))
  28. into result `Timestamp above maximum`;
  29. select
  30. $format(DateTime::EndOfYear(`tztimestamp`)),
  31. $format(DateTime::EndOfQuarter(`tztimestamp`)),
  32. $format(DateTime::EndOfMonth(`tztimestamp`)),
  33. $format(DateTime::EndOfWeek(`tztimestamp`)),
  34. $format(DateTime::EndOfDay(`tztimestamp`)),
  35. $format(DateTime::StartOf(`tztimestamp`, Interval("PT13H"))),
  36. $format(DateTime::StartOf(`tztimestamp`, Interval("PT4H"))),
  37. $format(DateTime::StartOf(`tztimestamp`, Interval("PT15M"))),
  38. $format(DateTime::StartOf(`tztimestamp`, Interval("PT20S"))),
  39. $format(DateTime::StartOf(`tztimestamp`, Interval("PT7S"))),
  40. from (
  41. select
  42. cast(ftztimestamp as TzTimestamp) as `tztimestamp`
  43. from Input
  44. )
  45. into result `Other cases`;