List:General Discussion« Previous MessageNext Message »
From:Michael Widenius Date:March 16 1999 2:34pm
Subject:odd date behavior..
View as plain text  
>>>>> "Alex" == Alex Krohn <alex@stripped> writes:

Alex> Hi,
Alex> This is due to my incorrect reading of how period_add works, but the
Alex> result was pretty odd, thought you might be interested:

mysql> create table test (a datetime);
Alex> Query OK, 0 rows affected (0.00 sec)

mysql> insert into test values (period_add(now(), 12));
Alex> Query OK, 1 row affected (0.05 sec)

mysql> select * from test;
Alex> +---------------------+
Alex> | a                   |
Alex> +---------------------+
Alex> | 2000-15-38 20:59:03 |
Alex> +---------------------+
Alex> 1 row in set (0.00 sec)

Alex> on my linux system running 3.22.14b-gamma. I was quite surprised that
Alex> mysql would allow that bad date in there (even though it was due to my
Alex> programming error).


The date was actually not bad.  The number: 1538205903 that you got
from period_add(), is obviously the same as:

001538205903  which in string form would be:

00-15-38 20:59:03

Saved as a datetime, you will get the stored datetime.

MySQL will not do any date/datetime checking, this is better left up
to the application.  It will only try to store the value you give it
as good as possible.

Alex> I've got it working properly using DATE_ADD(NOW(), INTERVAL 1 YEAR),
Alex> however is there a way to do the above nicely with 3.21.33 (where
Alex> date_add is not available).

How about:

SELECT concat(mid(NOW(),1,4)+1,mid(now(),5));

odd date behavior..Alex Krohn16 Mar
  • odd date behavior..Michael Widenius16 Mar
  • RE: Drumbeat 2000Jay Miller10 Jun