在StoredProcedure中,我们传递的日期如'From date'= 2014-08-12和'End Date'= 2015-06-24。如何在DB2中获取月份的初始日期
我想找到'From Date'= 2014-08-01和'End Date'= 2015-06-30。
在StoredProcedure中,我们传递的日期如'From date'= 2014-08-12和'End Date'= 2015-06-24。如何在DB2中获取月份的初始日期
我想找到'From Date'= 2014-08-01和'End Date'= 2015-06-30。
所以,你想从任何月份开始的时候开始,从任何月份开始到结束。
开始一个月的
last_day(fromdate) + 1 day - 1 month
末月
last_day(enddate)
的你可能会发现它很有用,以创建一个用户定义的函数,它封装了一个月的逻辑起点。
--Beginning of month
FromDate - (day(FromDate) -1) days
--End of the month
LAST_DAY(EndDate)
要获得当月的开始和结束的日期:
where date between (current_date - (day(current_date) - 1) days) and (current_date + 1 month - (day(current_date)) days)
你可能会想取代这个当前的日期与其他日期或最小值和最大值从其他表或结果。