1

I've got a really random bug in my code somewhere but can't figure it out. I'm inserting data into a MySQL Database based the current date and use the following statement;

INSERT INTO table VALUES (NULL,495297,str_to_date('19/01/2013 10:55:25','%d/%m/%y'),'English - UK',1,Str_to_date('17/01/2013','%d/%m/%y'),str_to_date('18/01/2013','%d/%m/%y'))

none of the dates work as the 19/01/2013 for some reason it becomes 19/01/2020, the next become 17/01/2020 and 18/01/2020! The latter two dates are listed as Date in data Type whereas the first date is DateTime so I don't know why this bizarre problem is happening.

Any help would be greatly appreciated.

Thanks Maudise

1 Answer 1

1

Use a capital %Y as identifier for the year:

INSERT INTO table VALUES (NULL,495297,str_to_date('19/01/2013 10:55:25','%d/%m/%Y'),'English - UK',1,Str_to_date('17/01/2013','%d/%m/%Y'),str_to_date('18/01/2013','%d/%m/%Y'))

The lower case %y specifies a year given by two digits (see MySQL documentation here and here). The uper-case %Y, however, is the four-digit version.

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

Comments

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.