I need to store some date in my SQL database, the problem is that the default storage is
YYYY-MM-DD
And I need
DD-MM-YYYY
My only solution was to store date as Varchars (10) and it’s working pretty well, but now I can’t order my queries by DATE, and I need to order them from the oldest to the newest…
Advertisement
Answer
There is no way to change the default date format for a MySQL date or either of its variants – DATETIME, TIMESTAMP and DATE.
Quoting the manual:
Although MySQL tries to interpret values in several formats, dates always must be given in year-month-day order (for example, '98-09-04'), rather than in the month-day-year or day-month-year orders commonly used elsewhere (for example, '09-04-98', '04-09-98').
Consider the native DATE_FORMAT() function as rightly suggested by @Micheal in his post.