【问题标题】:How to get the Initial date of the month in DB2如何在 DB2 中获取月份的初始日期
【发布时间】:2016-12-07 14:00:20
【问题描述】:

在 StoredProcedure 中,我们传递的日期类似于“起始日期”= 2014-08-12 和“结束日期”= 2015-06-24。

我想找到类似 'From Date' = 2014-08-01 和 'End Date' =2015-06-30。

【问题讨论】:

    标签: stored-procedures db2


    【解决方案1】:

    因此,您希望从作为 from 传入的任何月份的开始,到作为 end 传入的任何月份的结束。

    月初
    last_day(fromdate) + 1 day - 1 month

    月底
    last_day(enddate)

    您可能会发现创建一个封装月初逻辑的用户定义函数很有用。

    【讨论】:

      【解决方案2】:
      --Beginning of month
      FromDate - (day(FromDate) -1) days 
      
      --End of the month
      LAST_DAY(EndDate)
      

      【讨论】:

        【解决方案3】:

        获取当月开始和结束之间的日期:

        where date between (current_date - (day(current_date) - 1) days) and (current_date + 1 month - (day(current_date)) days)
        

        您可能希望将当前日期替换为另一个日期,或者其他表格或结果中的最小值和最大值。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-12-16
          • 2014-05-29
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多