全部产品

截取函数

更新时间:2019-03-05 15:48:21

DATE_TRUNC

  1. DATE_TRUNC('unit', timestamp)
  • 命令说明:根据指定的日期部分(如小时、周或月)截断时间戳表达式或文本。

  • 参数说明:unit可以是SECOND、MINUTE、HOUR、DAY、WEEK、MONTH、QUARTER或者YEAR。

    • SECOND:

    • MINUTE:

    • HOUR:

    • DAY:

    • WEEK:返回周一零点

    • MONTH:返回当月第一天零点

    • QUARTER:返回本季度第一天零点

    • YEAR:返回本年度第一天零点

  • 示例:

  1. select date_trunc('second', now());
  2. +--------------------+
  3. | _col0 |
  4. +--------------------+
  5. | 2018-12-27 14:08:53|
  6. +--------------------+
  7. select date_trunc('minute', now());
  8. +--------------------+
  9. | _col0 |
  10. +--------------------+
  11. | 2018-12-27 14:15:00|
  12. +--------------------+
  13. select date_trunc('hour', now());
  14. +--------------------+
  15. | _col0 |
  16. +--------------------+
  17. | 2018-12-27 14:00:00|
  18. +--------------------+
  19. select date_trunc('day', now());
  20. +--------------------+
  21. | _col0 |
  22. +--------------------+
  23. | 2018-12-27 00:00:00|
  24. +--------------------+
  25. select date_trunc('week', now());
  26. +--------------------+
  27. | _col0 |
  28. +--------------------+
  29. | 2018-12-24 00:00:00|
  30. +--------------------+
  31. select date_trunc('month', now());
  32. +--------------------+
  33. | _col0 |
  34. +--------------------+
  35. | 2018-12-01 00:00:00|
  36. +--------------------+
  37. select date_trunc('quarter', now());
  38. +--------------------+
  39. | _col0 |
  40. +--------------------+
  41. | 2018-10-01 00:00:00|
  42. +--------------------+
  43. select date_trunc('year', now());
  44. +--------------------+
  45. | _col0 |
  46. +--------------------+
  47. | 2018-01-01 00:00:00|