0

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.

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

That solved it thanks. I guess i still have to learn about date formatting.
1

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) );

1 Comment

Sorry, didn't know about that alternative.. I've always used DATE_ADD. Updated to match the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.