List:General Discussion« Previous MessageNext Message »
From:Graeme B. Davis Date:May 17 2000 2:06pm
Subject:Re: returning a sequence of days
View as plain text  

> On Tue, May 16, 2000 at 10:16:03AM -0400, Graeme B. Davis wrote:
> > Is it possible to have a SELECT statement that will return the
> > dates of X number of days.
> >
> > basically, I want to say "give me the YYYY-MM-DD for the next X
> > days" and it would return
> >
> > 2000-5-12
> > 2000-5-13
> > 2000-5-14
> > 2000-5-15
> >
> > is this possible?
>
> No.  MySQL doesn't have a procedural language (yet).  But there
> are plenty of host languages that can do this for you.
>
> If you're really wanting to do it in MySQL, you could try something
> like:
>
>     mysql> select @now := to_days(now()),
>         -> from_days(@now + 1) as first,
>         -> from_days(@now + 2) as second,
>         -> from_days(@now + 3) as third;
>     +------------------------+------------+------------+------------+
>     | @now := to_days(now()) | first      | second     | third      |
>     +------------------------+------------+------------+------------+
>     |                 730621 | 2000-05-17 | 2000-05-18 | 2000-05-19 |
>     +------------------------+------------+------------+------------+
>     1 row in set (0.01 sec)
>
> Make sure you're using a recent version of 3.23, or it won't work.
>
> Tim


Thanks for thew quick reply!  I'll give this a try.  I presume there is no
way to return the days as rows instead of columns, correct?  Also, I guess
I'm missing something... what is the @ notation you used in the above
snippet?  Just wondering.

Thanks alot,

Graeme

Thread
returning a sequence of daysGraeme B. Davis13 May
  • Re: returning a sequence of daysGraeme B. Davis16 May
    • Re: returning a sequence of daysThimble Smith17 May
  • Re: returning a sequence of daysJan Dvorak16 May
  • Re: returning a sequence of daysGraeme B. Davis17 May
    • Re: returning a sequence of daysThimble Smith18 May