如何获取MySQL中两个日期之间的月份列表

我必须获取mysql中两个日期之间的月份列表。

For Example:My Input is

From date 23-01-2013

To Date 01-04-2014

Output Should be

Jan 2013,

Feb 2013,

March 2013,

.

.

.

Jan 2014,

Feb 2014,

Mar 2014,

Apr 2014.

回答:

SQLFiddle演示

select 

DATE_FORMAT(m1, '%b %Y')

from

(

select

('2013-01-23' - INTERVAL DAYOFMONTH('2013-01-23')-1 DAY)

+INTERVAL m MONTH as m1

from

(

select @rownum:=@rownum+1 as m from

(select 1 union select 2 union select 3 union select 4) t1,

(select 1 union select 2 union select 3 union select 4) t2,

(select 1 union select 2 union select 3 union select 4) t3,

(select 1 union select 2 union select 3 union select 4) t4,

(select @rownum:=-1) t0

) d1

) d2

where m1<='2014-04-01'

order by m1

以上是 如何获取MySQL中两个日期之间的月份列表 的全部内容, 来源链接: utcz.com/qa/431767.html

回到顶部