Strange date behaviour

Strange date behaviour

am 31.03.2011 12:52:01 von Andrew Braithwaite

--MCBoundary=_111033111521002602
Content-Type: text/plain; charset=WINDOWS-1252
Content-Transfer-Encoding: quoted-printable

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?

Andrew

------------------------------------------------------------ ---------------=
------------------------------------------------------------ --
LOVEFiLM UK Limited is a company registered in England and Wales.=20
Registered Number: 06528297.=20
Registered Office: No.9, 6 Portal Way, London W3 6RU, United Kingdom.

This e-mail is confidential to the ordinary user of the e-mail address to w=
hich it was addressed. If you have received it in error,=20
please delete it from your system and notify the sender immediately.

This email message has been delivered safely and archived online by Mimecas=
t.
For more information please visit http://www.mimecast.co.uk=20
------------------------------------------------------------ ---------------=
------------------------------------------------------------ --
--MCBoundary=_111033111521002602--

Re: Strange date behaviour

am 31.03.2011 13:00:14 von Roy Lyseng

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

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql-2@m.gmane.org