How to get a list of months between 2 given dates using a query?

后端 未结 6 2357
不思量自难忘°
不思量自难忘° 2020-12-10 15:19

I have 2 dates, say 28-Mar-2011 and 29-Jun-2011. I need an sql query that will display the months between these 2 dates including the months containing the dates, ie. June,

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-10 15:31

    You can use the function MONTHS_BETWEEN

    SELECT MOD( TRUNC( MONTHS_BETWEEN( '2011-07-29', '2011-03-28' ) ), 12 ) as MONTHS
    FROM DUAL
    

    Output

        MONTHS
    ----------
             4
    

提交回复
热议问题