0
点赞
收藏
分享

微信扫一扫

MySQL datetime类型与时间、日期格式字符串大小比较

最后的执着 2022-04-03 阅读 67
mysql

一、前提

1、MySQL版本信息:

MySQL版本:8.0.27

注意:其他版本(主要5.x版本未验证)

2、表字段:

定义列

create_time datetime null comment '创建时间'
时间数据
idcreate_time
12022-04-01 23:00:00
22022-04-02 00:00:00
32022-04-02 00:00:01
4

2022-04-02 12:34:56

52022-04-02 23:59:59
62022-04-03 00:00:00

二、使用>、<、>=、<=比较

1.  >比较

a)   > 日期

select * from tab_a as t where t.create_time > '2022-04-02'

结果集:

idcreate_time
32022-04-02 00:00:01
42022-04-02 12:34:56
52022-04-02 23:59:59
62022-04-03 00:00:00

b) > 时间

select * from tab_a as t where t.create_time > '2022-04-02 00:00:00'

结果集:

idcreate_time
32022-04-02 00:00:01
42022-04-02 12:34:56
52022-04-02 23:59:59
62022-04-03 00:00:00
举报

相关推荐

0 条评论