I am familiar with DATE_FORMAT
function which can display the the record from my date field in the format specified. However, I would like to create a table with a date field that only accepts my format.
Here's what I have done so far:
CREATE TABLE test_table (
id INT AUTO_INCREMENT,
f_name VARCHAR(40) NOT NULL,
l_name VARCHAR(25) NOT NULL,
date_hired DATE NOT NULL
);
Inserting a record with a date_hired value of '2013-03-01' will be inserted as '1/03/2013 12:00:00 AM' which is far from my expected result (I would like the format the way it was inserted). Any feedback? Did I miss something?
Thanks,
Michael
The following is the output. The following is the query to format the date to YYYY-MM-DD. mysql> select str_to_date(LoginDate,'%d. %m.
MySQL comes with the following data types for storing a date or a date/time value in the database: DATE - format YYYY-MM-DD. DATETIME - format: YYYY-MM-DD HH:MI:SS. TIMESTAMP - format: YYYY-MM-DD HH:MI:SS.
MySQL recognizes DATE values in these formats: As a string in either ' YYYY-MM-DD ' or ' YY-MM-DD ' format. A “relaxed” syntax is permitted: Any punctuation character may be used as the delimiter between date parts. For example, '2012-12-31' , '2012/12/31' , '2012^12^31' , and '2012@12@31' are equivalent.
You can't change the format during table create, you can change the format of date for displaying user by using you programming logic like if you are using PHP as your server side language the you can convert it your desired format.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With