How to store date in mysql database?

I have a date in format dd/mm/yyyy. How can I save it in a databse if I fancy to do some operations on them after?


for example, I have to find out the lines where date > something

What type should I install on date field?

thank

+3
source share
4 answers

To store dates or times in MySQL, use , or . I would recommend the first two for most purposes. datedatetimetimestamp

To tell MySQL how to parse the date format, use the STR_TO_DATE function . Here is 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

, DATE_FORMAT. , , , - .

+10

date,

+1

date, , .

+1

Source: https://habr.com/ru/post/1746287/


All Articles