Basel
Basel

Reputation: 369

How to save a date in MySQL database with specific format?

I have insert query with the following information I want to put in MySQL database the problem that I have is with date value :

INSERT INTO odds (match_id, market_id, bookmaker_id, 3way_result_1, 3way_result_x, 3way_result_2, match_date) 
VALUES (1682572, 1, 21, 3.15, 1.00, 1.00, DATE_FORMAT(STR_TO_DATE('18.02.2014','%d.%m.%Y'), '%d.%m.%Y'))

str_to_date alone work fine (saved right date but with YYYY-mm-dd) but when i add DATE_FORMAT it saved as wrong value "2018-02-20"

I want to save it in the format of '18.02.2014'

can u correct my query?

Upvotes: 1

Views: 2312

Answers (2)

Thorsten Kettner
Thorsten Kettner

Reputation: 95101

Column match_date is a date column hopefully. So STR_TO_DATE already produces the needed date from the date string. Just remove the DATE_FORMAT part from your INSERT statement.

Upvotes: 0

Sanoob
Sanoob

Reputation: 2474

From this manual MySql date data type only allows you to use format YYYY-mm-dd to store. But while selecting data, you can use DATE_FORMAT to format your result as you wish.

Upvotes: 3

Related Questions