In MySQL table, why datetime type take inputs in Y-m-d H:i:s f开发者_开发技巧ormat?
Why can' it accepts inputs in d-m-Y H:i:s format?
MySQL uses the http://en.wikipedia.org/wiki/ISO_8601 format for dates. This is an international standard. It is also the only date format used by MySQL.
This format has the added advantage that is sorts correctly in a natural way, as the order YYYY-MM-DD HH:MM:SS is nicely ordered from less to more specific.
You can use the http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format function to format that kind of date into any desired form, or you are doing this client-side using functions of your host language.
It depends on server variables.
Run this query to see them -
SHOW VARIABLES LIKE 'date%format';
Have a look at the manual about date_format and datetime_format options.
This is mysql standard to accept the date. You have to pass it in the specified format.
There should be an standard to accept and store the date internally mysql chosen yyyy-mm-dd
format.
Think if there is no standard how mysql internally determine what format the date is stored in database and how proceed with dates.
Your are sending date in dd-mm-yyy
02-02-2011
other people is sending mm-dd-yyyy
02-03-2011
. If there is no standard for date format it is impossible to determine the month and date in above example.
Mysql chosen it to be YYYY-mm-dd
精彩评论