----- Original Message ----- 
From: "Alan Williamson" <[EMAIL PROTECTED]>
To: "Jigal van Hemert" <[EMAIL PROTECTED]>
Sent: Wednesday, March 31, 2004 2:05 PM
Subject: Re: CURDATE() bug?


> Jigal van Hemert wrote:
>
>
> > NOT A BUG!!!
> >
> > In the manual it is stated that CURDATE() returns either YYYY-MM-DD or
> > YYYYMMDD depending on the context.
> > So in the context of addition with an integer it will return YYYYMMDD
which
> > is automatically cast to integer when adding either 0 or 1.
>
> sorry ... but disagree with you, it is a bug.  Casting is a very
> dangerous business at the best of times.  It is a bug.  Its a hack.  But
> hacks can be good.  However, one can't make assumptions on hacks.  The
> documentation is not clear at all in this area.  The value in which you
> cast is important; so your assumption that 0 or 1 makes no difference is
> incorrect.
>
> Simply an addition to the documentation to clarify that this is purely a
> formatting hack and should not be used to do date addition would satisfy
> all.

RTFM!
It gives you plenty of examples for manipulating dates and the output of of
curdate() is clearly stated with examples.

No-one can help it that you don't like it the way it is.
You provided the same example as the manual (CURDATE() + 0) and got the same
result as the manual says.
Then you do an addition and you're surprised that the result is an integer?

Have you tried something like SELECT '1tt' +2; ? The result may be a
surprise for you (3), but if you read the manual about how MySQL handles
types (e.g. http://www.mysql.com/doc/en/String_comparison_functions.html) it
is expected behaviour and not a bug IMHO.

The fact that something takes different values in different contexts is not
very strange. Languages such as Perl will give you various examples.
The +0 is not a hack, but provides a numerical context for the function
CURDATE(), which modifies its behaviour.

Regards, Jigal.



-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to