Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)

I am having a column called 'today' and the type is 'DATE' in MySQL.

When I am trying to add the date in the format '07-25-2012' I am getting the below error:

Unable to run query:Incorrect date value: '07-25-2012' for column

1 Answer

0 votes
by (12.7k points)

As MySQL accepts the date in the y-m-d format in date type column, you need to STR_TO_DATE function to convert the date into yyyy-mm-dd format for insertion in the following way:

INSERT INTO table_name(today) 
VALUES(STR_TO_DATE('07-25-2012','%m-%d-%y')); 

Similarly, if you want to select the date in a different format other than MySQL format, you should try DATE_FORMAT function

SELECT DATE_FORMAT(today, '%m-%d-%y') from table_name;

Want to be a SQL expert? Intellipaat's SQL Certification will be your best choice. Go ahead with the training!

Related questions

0 votes
1 answer
asked Dec 26, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
asked Dec 4, 2020 in SQL by Appu (6.1k points)
0 votes
1 answer
0 votes
1 answer
asked Jul 15, 2019 in SQL by Tech4ever (20.3k points)
0 votes
2 answers

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...