I cannot seem to find any info on this..
I need to convert a string to a date so that it will import properly to an SQL DATE field. When I import 12/25/2012 to the DB, it appears as 0000-00-00.
What’s the proper way to do this?
Links and refs appreciated.
As @Ravi pointed out in his answer, MySQL accepts dates in the format
YYYY-MM-DD. Quoted from 11.1.5. Date and Time Types1:For this, you can use
str_todate()2 function to format it:SQL Fiddle Demo
This way, these input strings will be stored in your database as date objects(without any specific date format). Later, if you want to output these dates in a specific format you can use
DATE_FORMAT3 to format it. Something like:1, 2, 3: Links and refs, that you asked for.