Strange date behaviour

--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.
Registered Number: 06528297.
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,
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
------------------------------------------------------------ ---------------=
------------------------------------------------------------ --
--MCBoundary=_111033111521002602--
Andrew Braithwaite [ Do, 31 März 2011 12:52 ] [ ID #2057393 ]

Re: Strange date behaviour

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 [at] m.gmane.org
Roy Lyseng [ Do, 31 März 2011 13:00 ] [ ID #2057394 ]
Datenbanken » gmane.comp.db.mysql.general » Strange date behaviour

Vorheriges Thema: Parse text field from query
Nächstes Thema: getting procedure code via mysqldump