After googling around, I cannot find a way to create a new table with a DATETIME
column with the default format set to 'DD-MM-YYYY HH:MM:SS
'
I saw a tutorial in which it was done in phpmyadmin
so I suspect that I could use mysql via command line and achieve the same thing when creating my new table with
CREATE TABLE ()
Thank you in advance
MySQL retrieves and displays DATETIME values in ' YYYY-MM-DD hh:mm:ss ' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59' . The TIMESTAMP data type is used for values that contain both date and time parts.
The MySQL DATE_FORMAT() function formats a date value with a given specified format. You may also use MySQL DATE_FORMAT() on datetime values and use some of the formats specified for the TIME_FORMAT() function to format the time value as well.
In the MySQL documentation shows the following example: CREATE TABLE t1 ( ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP, dt DATETIME DEFAULT CURRENT_TIMESTAMP );
Change the curdate() (current date) format in MySQL The current date format is 'YYYY-mm-dd'. To change current date format, you can use date_format().
"MySQL retrieves and displays DATETIME values in 'YYYY-MM-DD HH:MM:SS' format." This is from mysql site. You can store only this type, but you can use one of the many time format functions to change it, when you need to display it.
Mysql Time and Date functions
For example, one of those functions is the DATE_FORMAT, which can be used like so:
SELECT DATE_FORMAT(column_name, '%m/%d/%Y %H:%i') FROM tablename
Use DATE_FORMAT function to change the format.
SELECT DATE_FORMAT(CURDATE(), '%d/%m/%Y') SELECT DATE_FORMAT(column_name, '%d/%m/%Y') FROM tablename
Refer DOC for more details
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