愿所有的美好和期待都能如约而至

检查当前日期是否在两个日期之间 Oracle SQL

发布时间:  来源:互联网  作者:匿名  标签:between date error Check if current date is between two dates Oracle SQL excepti  热度:37.5℃

本文介绍了检查当前日期是否在两个日期之间 Oracle SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果当前日期介于 2 个日期之间,我想通过 Oracle SQL 选择 1.

I would like to select 1 if current date falls between 2 dates through Oracle SQL.

我在阅读其他问题后写了一个 SQL.

I wrote an SQL after reading through other questions.

https://stackoverflow.com/questions/2369222/oracle-date-between-query

https://stackoverflow.com/questions/2399753/select-from-table-by-knowing-only-date-without-time-oracle

但它只返回空值.sysdate01/05/2014 的当前日期,日期格式为DD/MM/YYYY.

But it returned only null. sysdate is the current date that is 01/05/2014 in date format DD/MM/YYYY.

我写的SQL是:

select 1 from dual 
WHERE to_date(sysdate,'DD/MM/YYYY') 
BETWEEN TO_DATE('28/02/2014', 'DD/MM/YYYY')
AND TO_DATE('20/06/2014', 'DD/MM/YYYY');

select 1 from dual 
WHERE to_date(sysdate,'DD/MM/YYYY') >= TO_DATE('28/02/2014', 'DD/MM/YYYY') 
AND to_date(sysdate,'DD/MM/YYYY') < TO_DATE('20/06/2014', 'DD/MM/YYYY'); 

推荐答案

您不需要将 to_date() 应用到 sysdate.它已经在那里了:

You don’t need to apply to_date() to sysdate. It is already there:

select 1
from dual 
WHERE sysdate BETWEEN TO_DATE('28/02/2014', 'DD/MM/YYYY') AND TO_DATE('20/06/2014', 'DD/MM/YYYY');

如果你关心日期上的时间分量,那么使用trunc():

If you are concerned about the time component on the date, then use trunc():

select 1
from dual 
WHERE trunc(sysdate) BETWEEN TO_DATE('28/02/2014', 'DD/MM/YYYY') AND
                             TO_DATE('20/06/2014', 'DD/MM/YYYY');

这篇关于检查当前日期是否在两个日期之间 Oracle SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,

勇敢去编程!

勇敢的热爱编程,未来的你一定会大放异彩,未来的生活一定会因编程更好!

TOP