List:General Discussion« Previous MessageNext Message »
From:Roy Lyseng Date:March 31 2011 11:00am
Subject:Re: Strange date behaviour
View as plain text  
On 31.03.11 12.52, Andrew Braithwaite wrote:
> Hi,
>
> Mysql>  select curdate() + interval 6 month - interval 6 month;
> +-------------------------------------------------+
> | curdate() + interval 6 month - interval 6 month |
> +-------------------------------------------------+
> | 2011-03-30                                      |
> +-------------------------------------------------+
> 1 row in set (0.00 sec)
>
> Any ideas why this is wrong?

Interval arithmetic is tricky...

curdate() is 2011-03-31, which is the last date of March.
Adding 6 months gives the last date of september, ie 2011-09-30, subtracting 6 
months gives 2011-03-30.

My best recommendation is "don't do it".

Hope this helps,
Roy
Thread
Strange date behaviourAndrew Braithwaite31 Mar
  • Re: Strange date behaviourRoy Lyseng31 Mar