M.I.T.
M.I.T.

Reputation: 1042

MySql Store Date like YYYY/MM/DD

i have a database structure like this

name          |   birthdate
---------------------------------
varcahr(255)  |    date

i am inserting date in (yyyy/mm/dd) like this using jquery date pickeer '1985/08/22'

but Mysql store it like '1985-08-22'

there is any way that i can store date like '1985/08/22' i want to store slash not '-'.

Upvotes: 1

Views: 3359

Answers (3)

Steven Mastandrea
Steven Mastandrea

Reputation: 2772

You should store the data in the native date format, for efficiency in calculation, etc. You can control the format of the dates going into the tables and selecting from them in your queriers. For example, you can insert data using the str_to_date function:

INSERT into table1(birthdate) 
VALUES STR_TO_DATE('2009/01/01','%m/%d/%y')

For selecting your date, you can use

SELECT DATE_FORMAT(birthdate, '%m/%d/%y') 
FROM table1

Upvotes: 3

Josua M C
Josua M C

Reputation: 3158

INSERT INTO table (name, birthdate) VALUES(
            'mit', STR_TO_DATE('2009/03/08', '%Y/%m/%d'));

Upvotes: 0

juergen d
juergen d

Reputation: 204924

MySQL does not store the date as a specific string. It only represents dates like that. See DATE_FORMAT to display a speccific date representation.

Upvotes: 1

Related Questions