msyql date datetime

对于 mysql 的 datetime 列,如果你 insert 的是 date(只有年月日),那么实际写入时会把时分秒设置为0 从而保存到数据库

mysql> CREATE TABLE `zzz0210`
-> (`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'ID',
->  `age` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '年龄',
->  `name` varchar(60) NOT NULL DEFAULT '' COMMENT '名字',
->  `address` varchar(60) NOT NULL DEFAULT '' COMMENT '地址',
->  
->  `created_date` date NOT NULL  COMMENT '创建日期',
->  `created_datetime` datetime(6) NOT NULL COMMENT '创建年月日时分秒',
->  PRIMARY KEY (`id`)
-> )COMMENT = '学生表';
Query OK, 0 rows affected (0.36 sec)
mysql> 
mysql> 
mysql> insert into zzz0210 values(1,22,'rob', 'bj', '2020:02:09', '2020:02:09 11:11:11');
Query OK, 1 row affected (0.09 sec)
mysql> 
mysql> 
mysql> insert into zzz0210 values(2,22,'rob', 'bj', '2020:02:09', '2020:02:08');
Query OK, 1 row affected (0.11 sec)
mysql> 
mysql> 
mysql> select * from zzz0210;
+----+-----+------+---------+--------------+----------------------------+
| id | age | name | address | created_date | created_datetime           |
+----+-----+------+---------+--------------+----------------------------+
|  1 |  22 | rob  | bj      | 2020-02-09   | 2020-02-09 11:11:11.000000 |
|  2 |  22 | rob  | bj      | 2020-02-09   | 2020-02-08 00:00:00.000000 |
+----+-----+------+---------+--------------+----------------------------+
2 rows in set (0.00 sec)

mysql> 

你可能感兴趣的:(数据库)