Teradata中的日期/时间计算

时间:2014-03-19 18:58:00

标签: date time teradata

请帮我计算teradata中的一天的开始,一天的结束,月的开始,一个月的结束(以及最多3个地方的时间)。我想要这样的'2014-03-01 00:00:00.000';感谢

1 个答案:

答案 0 :(得分:0)

这应该让你开始:

SELECT DATE
     , CAST(DATE AS INTEGER) AS DateInteger
     , CAST(((DATE / 100) * 100) + 1 AS DATE) AS MonthBegin
     , CAST((((DATE / 100) +1 ) * 100) + 1 AS DATE) AS NextMonthBegin
     , CAST((((DATE / 100) +1 ) * 100) + 1 AS DATE)  - 1 AS MonthEnd
     , CURRENT_TIMESTAMP(3)
     , CAST(CAST(CURRENT_TIMESTAMP(3) AS DATE) AS TIMESTAMP(3)) AS DayBegin
     , CAST((CAST(CURRENT_TIMESTAMP(3) AS DATE) + 1) AS TIMESTAMP(3)) - INTERVAL '0.001' SECOND AS DayEnd

*编辑*

SELECT CURRENT_DATE
     , CURRENT_DATE - EXTRACT( DAY FROM CURRENT_DATE) + 1 as MonthBegin
     , ADD_MONTHS(( CURRENT_DATE - EXTRACT (DAY FROM CURRENT_DATE) + 1), 1) as NextMonthBegin
     , ADD_MONTHS(( CURRENT_DATE - EXTRACT (DAY FROM CURRENT_DATE) + 1), 1) - 1 as MonthEnd
     , CURRENT_TIMESTAMP(3)
     , CAST( CAST(CURRENT_TIMESTAMP (3) AS DATE) AS TIMESTAMP (3)) AS DayBegin
     , CAST(( CAST(CURRENT_TIMESTAMP (3) AS DATE) + 1) AS TIMESTAMP (3)) - INTERVAL '0.001' SECOND AS DayEnd;

从这里开始,您应该能够以月开始,月末和下个月开始作为时间戳。如果你遇到困难,请告诉我。