Get a list of dates between two dates

后端 未结 20 2106
醉梦人生
醉梦人生 2020-11-22 00:26

Using standard mysql functions is there a way to write a query that will return a list of days between two dates.

eg given 2009-01-01 and 2009-01-13 it would return

20条回答
  •  独厮守ぢ
    2020-11-22 00:50

    We used this in our HRMS System you will find it useful

    SELECT CAST(DAYNAME(daydate) as CHAR) as dayname,daydate
        FROM
        (select CAST((date_add('20110101', interval H.i*100 + T.i*10 + U.i day) )as DATE) as daydate
          from erp_integers as H
        cross
          join erp_integers as T
        cross
          join erp_integers as U
         where date_add('20110101', interval H.i*100 + T.i*10 + U.i day ) <= '20110228'
        order
            by daydate ASC
            )Days
    

提交回复
热议问题