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
i have used following line of code & it works fine Thanks.... @Mithun Sasidharan **
**
"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 to like so:
Use DATE_FORMAT function to change the format.
Refer DOC for more details
As others have explained that it is not possible, but here's alternative solution, it requires a little tuning, but it works like datetime column.
I started to think, how I could make formatting possible. I got an idea. What about making trigger for it? I mean, adding column with type
char
, and then updating that column using a MySQL trigger. And that worked! I made some research related to triggers, and finally come up with these queries:You can't use
TIMESTAMP
orDATETIME
as a column type, because these have their own format, and they update automatically.So, here's your alternative timestamp or datetime alternative! Hope this helped, at least I'm glad that I got this working.
I'm pretty certain that you can't change the datetime format in mysql. The phpmyadmin setting is probably applying a custom format as it reads the datetime (using DATE_FORMAT or something from php). It shouldn't matter what format the database uses, format in the application to display it as you wish.
Date formatting is a pretty common task. I typically like to abstract it out into internationalization code or, if you don't need to deal with i18n, into a common date utility library. It helps keep things consistent and makes it easier to change later (or add i18n support).
This cannot be done for the table; besides, you even cannot change this default value at all.
The answer is a server variable datetime_format, it is unused.