A
A
Alexander Srokin2017-08-15 14:23:30
MySQL
Alexander Srokin, 2017-08-15 14:23:30

How to get a list of dates in MySQL?

Good afternoon!
It is required to get a list of several recent dates, starting from today. Is it possible in MySQL (Version 5.7) to do this in a nicer way than the one below?

SELECT date(now()) as 'date'
union all
SELECT date(SUBDATE(now(), 1)) as 'date'
union all
SELECT date(SUBDATE(now(), 2)) as 'date'
union all
SELECT date(SUBDATE(now(), 3)) as 'date'
union all
SELECT date(SUBDATE(now(), 4)) as 'date';

Thanks in advance for your reply!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2017-08-15
@AlexMaxTM

I don't quite understand the word "beautiful"

SELECT 
date(now()) as 'date',  
date(SUBDATE(now(), 1)) as 'date1', 
date(SUBDATE(now(), 2)) as 'date2',
date(SUBDATE(now(), 3)) as 'date3',
date(SUBDATE(now(), 4)) as 'date4'

So more beautiful?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question