Reputation: 543
I have this mysql statement and it's giving me error:
INSERT INTO envios ( fecha_estimada_entrega) VALUES (ADDDATE('15/10/2011', INTERVAL 8 DAY));
When i run it i get this meesage:
#1048 - Column 'fecha_estimada_entrega' cannot be null
Can you please help me out on this?
I'm sure it's quite simple, but my head is burned.
Thanks.
Upvotes: 0
Views: 78
Reputation: 434585
Try changing your date format to the standard ISO 8601 format:
INSERT INTO envios (fecha_estimada_entrega)
VALUES (ADDDATE('2011-10-15', INTERVAL 8 DAY));
MySQL is probably trying to parse 15 as a month number, failing, and converting your '15/10/2011'
date to NULL. Switching to ISO 8601 (the one true date format BTW) gets me sensible results:
mysql> select ADDDATE('2011-10-15', INTERVAL 8 DAY);
+---------------------------------------+
| ADDDATE('2011-10-15', INTERVAL 8 DAY) |
+---------------------------------------+
| 2011-10-23 |
+---------------------------------------+
As an aside, you should always use ISO 8601 date and time formats internally and limit other formats to the edges (i.e. user input and final display). You'll save yourself a lot of trouble that way and they'll even sort properly as strings.
Upvotes: 2
Reputation: 25572
You need to provide a date format which MySQL understands (ex. Y-M-D).
INSERT INTO envios ( fecha_estimada_entrega )
VALUES ( ADDDATE('2011-10-15', INTERVAL 8 DAY) );
Upvotes: 1