9

Is there a way to generate dates between date ranges. After looking on SO I found out there is a way to use CTE, another option is to use Union All from 0 to 9. Is there an inbuilt function which I can use to generate dates between date range?

We are using MySQL 8.0.

asked Dec 5, 2018 at 9:28
3
  • 1
    Is there an inbuilt function No. For your version - use recursive CTE. Commented Dec 5, 2018 at 9:42
  • Moreover, there is no table data type, so both any built-in function and possibility to create user-definad function with the output of table-type not exists. Commented Dec 5, 2018 at 9:56
  • 1
    (MariaDB has sequence-generating pseudo-tables.) Commented Dec 5, 2018 at 16:41

1 Answer 1

22

I tried this solution :

WITH recursive Date_Ranges AS (
 select '2018-11-30' as Date
 union all
 select Date + interval 1 day
 from Date_Ranges
 where Date < '2018-12-31')
select * from Date_Ranges;
Kondybas
4,81020 silver badges16 bronze badges
answered Dec 6, 2018 at 10:07

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.