List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:March 28 2004 10:40pm
Subject:Re: to_days() error?
View as plain text  
At 16:23 -0600 3/28/04, unruhtech wrote:
>the following works:
>SELECT to_days( curdate() + 0 ) , to_days( curdate() + 3 ) FROM table
>732033 732036

That's correct.

>
>but this does not:
>SELECT to_days( curdate() + 0 ) , to_days( curdate() + 4 ) FROM table
>732033 NULL

That's correct.  CURDATE() + 4 is the number 20040332, which can't
be interpreted as a date by TO_DAYS() -- 32 isn't a valid day in
any month.

You could use this expression instead:

TO_DAYS(CURDATE() + INTERVAL 4 DAY);

Or just TO_DAYS(CURDATE()) + 4.

>
>an end of month problem or a curdate() problem or what?
>
>curdate( ) + 0,  curdate( ) + 7 
>20040328 20040335
>
>no month i know of has 35 days in it.

You're right.  But the *number* 20040328 plus 7 *does* equal 20040335.

You're thinking that the value of CURDATE() when used in a numeric
context is actually a date, right?  It's a number.

>
>3.23.58 on red hat 7.3
>
>Steve
>
>p.s. any tips for a query on today and today +7 days?

TO_DAYS(CURDATE()) + 7 rather than TO_DAYS(CURDATE() + 7)
will probably give you results more like what you're expecting.
Or TO_DAYS(CURDATE() + INTERVAL 7 DAY).


-- 
Paul DuBois, MySQL Documentation Team
Madison, Wisconsin, USA
MySQL AB, www.mysql.com

MySQL Users Conference: April 14-16, 2004
http://www.mysql.com/uc2004/
Thread
to_days() error?unruhtech29 Mar
  • Re: to_days() error?Daniel Kasak29 Mar
  • Re: to_days() error?Paul DuBois29 Mar
    • Limiting the data returned to just what I needScott Haneda29 Mar
      • Re: Limiting the data returned to just what I needUnknown Sender29 Mar
      • Re: Limiting the data returned to just what I needMichael Stassen29 Mar