检查当前日期是否在两个日期之间 Oracle SQL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23398632/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Check if current date is between two dates Oracle SQL
提问by Avinesh Kumar
I would like to select 1
if current date falls between 2 dates through Oracle SQL.
我想1
通过 Oracle SQL选择当前日期是否介于 2 个日期之间。
I wrote an SQL after reading through other questions.
我在阅读其他问题后写了一个 SQL。
https://stackoverflow.com/questions/2369222/oracle-date-between-query
https://stackoverflow.com/questions/2369222/oracle-date-between-query
But it returned only null. sysdate
is the current date that is 01/05/2014
in date format DD/MM/YYYY
.
但它只返回空值。sysdate
是01/05/2014
日期格式的当前日期DD/MM/YYYY
。
The SQL I wrote is:
我写的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');
and
和
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');
回答by Gordon Linoff
You don't need to apply to_date()
to sysdate
. It is already there:
你不需要申请to_date()
到sysdate
。它已经存在:
select 1
from dual
WHERE sysdate BETWEEN TO_DATE('28/02/2014', 'DD/MM/YYYY') AND TO_DATE('20/06/2014', 'DD/MM/YYYY');
If you are concerned about the time component on the date, then use trunc()
:
如果您担心日期上的时间部分,请使用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');
回答by arun
SELECT to_char(emp_login_date,'DD-MON-YYYY HH24:MI:SS'),A.*
FROM emp_log A
WHERE emp_login_date BETWEEN to_date(to_char('21-MAY-2015 11:50:14'),'DD-MON-YYYY HH24:MI:SS')
AND
to_date(to_char('22-MAY-2015 17:56:52'),'DD-MON-YYYY HH24:MI:SS')
ORDER BY emp_login_date
回答by user6341745
TSQL: Dates- need to look for gaps in dates between Two Date
TSQL:日期 - 需要查找两个日期之间的日期间隔
select
distinct
e1.enddate,
e3.startdate,
DATEDIFF(DAY,e1.enddate,e3.startdate)-1 as [Datediff]
from #temp e1
join #temp e3 on e1.enddate < e3.startdate
/* Finds the next start Time */
and e3.startdate = (select min(startdate) from #temp e5
where e5.startdate > e1.enddate)
and not exists (select * /* Eliminates e1 rows if it is overlapped */
from #temp e5
where e5.startdate < e1.enddate and e5.enddate > e1.enddate);