Reputation: 1
I have a table db2admin.shdl_dtl in which there are two columns for the date-
startdate enddate
from these two date columns I want to show months between two dates
i.e. startdate = '2015-01-05' and enddate = '2015-04-20' then output of the query should come like this-
Output- jan, feb, mar, apr
Upvotes: 0
Views: 2682
Reputation: 67
with cte (diffmonths,monthdiff) as
(select date(startdate ) as diffmonths,0 from sysibm.sysdummy1
union all
select date(diffmonths) + 1 month as diffmonths,month(diffmonths) from cte
where diffmonths<=(date(enddate)) )
select * from cte where MONTHDIFF >0
Upvotes: 1