要在MySQL中存储日期,请使用STR_TO_DATE()方法-
insert into yourTableName values(STR_TO_DATE('yourDate', '%d/%m/%Y'));
让我们首先创建一个表-
create table DemoTable ( AdmissionDate date );
使用插入命令在表中插入记录-
insert into DemoTable values(STR_TO_DATE('10/01/2013', '%d/%m/%Y')); insert into DemoTable values(STR_TO_DATE('31/01/2015', '%d/%m/%Y')); insert into DemoTable values(STR_TO_DATE('23/04/2019', '%d/%m/%Y')); insert into DemoTable values(STR_TO_DATE('01/03/2019', '%d/%m/%Y'));
使用选择命令显示表中的记录-
select *from DemoTable;
这将产生以下输出-
+---------------+ | AdmissionDate | +---------------+ | 2013-01-10 | | 2015-01-31 | | 2019-04-23 | | 2019-03-01 | +---------------+ 4 rows in set (0.00 sec)