Reputation: 133
How to insert this date format on my table: 30/12/2018
?
If it's impossible, then how can i turn this date format: 2018-12-30 12:10:00
to 30/12/2018
on a echo
?
Upvotes: 0
Views: 142
Reputation: 222682
You should proceed as follows :
STR_TO_DATE
to convert strings to dates before writing to database DATE_FORMAT
to format the datetime values to the relevant format when reading form database.Here is a small example of CREATE/INSERT/SELECT
:
CREATE TABLE mytable (
mydate datetime
);
INSERT INTO mytable
VALUES (STR_TO_DATE('30/12/2018', '%d/%m/%Y'));
SELECT DATE_FORMAT(mydate, '%d/%m/%Y')
FROM mytable;
Upvotes: 0
Reputation: 1271111
Store the date/time in the native format (i.e. as a datetime
or date
). Then, use date_format()
to convert it to the format you want on output:
select date_format(datecol, '%d/%m/%Y')
Upvotes: 3