MySQL Forums
Forum List  »  Newbie

Generate sequence of dates
Posted by: Steve Lawrence
Date: April 14, 2005 12:50PM

Greetings. I was perusing the Variables feature of MySQL and thought it might be the solution to a problem I am having, but no luck. What I would like to do is generate a result set containing the next 21 days, starting from today. I tried:

set @startDay=CURDATE();
set @endDay = DATE_ADD(CURDATE(),INTERVAL 21 DAY);
set @day = @startDay;
SELECT @day:=DATE_ADD(@day:,INTERVAL 1 DAY) AS Day from Employee where @day < @endDay;

but there is lots of things wrong with this:
1: you can't assign a variable and reference it in the same select.
2: you can't reference a variable in a where clause.

Can any of you point me in the right direction to accomplish this? I would rather do it in the DB query than do it in PHP, which is what I have to do now.

Options: ReplyQuote


Subject
Written By
Posted
Generate sequence of dates
April 14, 2005 12:50PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.