Check if current date is between two dates Oracle SQL

前端 未结 3 1358
攒了一身酷
攒了一身酷 2020-11-30 03:42

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

I wrote an SQL after reading through other questions.

https:/

相关标签:
3条回答
  • 2020-11-30 04:06

    TSQL: Dates- need to look for gaps in dates between Two Date

    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);
    
    0 讨论(0)
  • 2020-11-30 04:11
    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
    
    0 讨论(0)
  • 2020-11-30 04:22

    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');
    

    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');
    
    0 讨论(0)
提交回复
热议问题