且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将日期时间转换为日期,截断时间并留下日期?

更新时间:2023-02-03 15:36:07

如果要在SELECT语句中使用它,只需使用DATE运算符:

If you want this in a SELECT-Statement, just use the DATE Operator:

SELECT DATE(`yourfield`) FROM `yourtable`;

如果要在结构上更改表,只需将数据类型更改为DATE(当然,只有在不影响依赖于此字段的应用程序的情况下,才这样做).

If you want to change the table structurally, just change the datatype to DATE (of course only do this if this doesn't affect applications depending on this field).

ALTER TABLE `yourtable` CHANGE `yourfield` `yourfield` DATE;

两者都会消除时间部分.

Both will eliminate the time part.