首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >sql中datetime日期类型字段比较(mysql&oracle)

sql中datetime日期类型字段比较(mysql&oracle)

作者头像
红目香薰
发布于 2022-11-29 18:25:57
发布于 2022-11-29 18:25:57
5.7K0
举报
文章被收录于专栏:CSDNToQQCodeCSDNToQQCode

mysql

可以直接用大于号,也可以用  between  and

代码语言:javascript
复制
SELECT * FROM users WHERE UPDATE_DATE >= '2021-08-12 11:22:09' AND UPDATE_DATE <= '2021-08-15 11:22:33';

SELECT * FROM users WHERE UPDATE_DATE BETWEEN '2021-08-12 11:22:09' AND '2021-08-15 11:22:33';

Oracle

oracle sql日期比较:

在今天之前:

代码语言:javascript
复制
select * from up_date where update < to_date('2021-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')
select * from up_date where update <= to_date('2021-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')

在今天只后:

代码语言:javascript
复制
select * from up_date where update > to_date('2022-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')
select * from up_date where update >= to_date('2022-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')

精确时间:

代码语言:javascript
复制
select * from up_date where update = to_date('2022-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')

在某段时间内:

代码语言:javascript
复制
select * from up_date where update between to_date('2022-07-07 00:00:00','yyyy-mm-dd hh24:mi:ss') and to_date('2022-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')
select * from up_date where update < to_date('2022-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss') and update > to_date('2022-07-07 00:00:00','yyyy-mm-dd hh24:mi:ss')
select * from up_date where update <= to_date('2022-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss') and update >= to_date('2022-07-07 00:00:00','yyyy-mm-dd hh24:mi:ss')
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-01-09,如有侵权请联系 cloudcommunity@tencent.com 删除
目录
  • mysql
  • Oracle
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档