views:

65

answers:

4

i have date in dd/mm/yyyy format. how can i store it in databse, if i fant to do some operations on them after?


for example i must find out the rows, where date > something

what type i must set to date field?

thanks

+5  A: 

To store dates or times in MySQL use date, datetime or timestamp. I'd recommend the first two for most purposes.

To tell MySQL how to parse your date format use the STR_TO_DATE function. Here's an example:

CREATE TABLE table1 (`Date` Date);
INSERT INTO table1 (`Date`) VALUES (STR_TO_DATE('01/05/2010', '%m/%d/%Y'));
SELECT * FROM table1;

Date
2010-01-05

To format the results back into the original form look at the DATE_FORMAT function. Note that you only need to format it if you want to display it as a string using something other than the default format.

Mark Byers
@Mark Byers but when i use timestamp, it looks like this 0000-00-00 00:00:00, when i try to save for example 21/05/2010 date
Syom
@Syon: I've updated my answer with an example.
Mark Byers
A: 

or just date if you don't need time information

st3
A: 

Use date if you only care about the date and not about the exact time.

Itamar Bar-Lev