Home » SQL & PL/SQL » SQL & PL/SQL » Sysdate between Two date columns (Oracle 11g)
Sysdate between Two date columns [message #578248] Tue, 26 February 2013 01:49 Go to next message
srinivas.k2005
Messages: 303
Registered: August 2006
Senior Member
Hi,

I need to fetch Data from a table X where current date(Sysdate) lies between the datecolumns
Active_From and Active_To.

Active_From and Active_To are date columns.


Create table X(
 ID number,
Active_From date,
Active_To date
)

Insert into X values (1, sysdate-3,sysdate + 3);

Insert into X values (1, sysdate-2,sysdate + 3);

Insert into X values (1, sysdate-3,sysdate +3);



Thanks,
SRK
Re: Sysdate between Two date columns [message #578249 is a reply to message #578248] Tue, 26 February 2013 01:52 Go to previous messageGo to next message
Littlefoot
Messages: 19693
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
So, where's the problem? Just translate your sentence into Oracle SQL.
Re: Sysdate between Two date columns [message #578299 is a reply to message #578249] Tue, 26 February 2013 12:34 Go to previous messageGo to next message
Bill B
Messages: 1118
Registered: December 2004
Senior Member
a hint....Use the between clause
Re: Sysdate between Two date columns [message #578378 is a reply to message #578299] Wed, 27 February 2013 06:19 Go to previous messageGo to next message
bharathi89
Messages: 39
Registered: May 2012
Location: chennai
Member
Hi, Here is the Query You Want...

SELECT *
FROM X
WHERE TRUNC (SYSDATE) BETWEEN ACTIVE_FROM AND ACTIVE_TO;

Regards
Bharathi.CV
Re: Sysdate between Two date columns [message #578393 is a reply to message #578378] Wed, 27 February 2013 08:13 Go to previous messageGo to next message
joy_division
Messages: 4529
Registered: February 2005
Location: East Coast USA
Senior Member
cvbharathi89 wrote on Wed, 27 February 2013 07:19
Hi, Here is the Query You Want...

SELECT *
FROM X
WHERE TRUNC (SYSDATE) BETWEEN ACTIVE_FROM AND ACTIVE_TO;


Ummm...no. Use of TRUNC is incorrect.
Re: Sysdate between Two date columns [message #578394 is a reply to message #578248] Wed, 27 February 2013 08:16 Go to previous message
Bill B
Messages: 1118
Registered: December 2004
Senior Member
if the active_from and active_to are non truncated dates (includes time) then don't use trunc. If they are truncated then you would have to.
Previous Topic: Avoid divisions by zero
Next Topic: Regular expression
Goto Forum:
  


Current Time: Thu Oct 23 09:08:20 CDT 2014

Total time taken to generate the page: 0.08424 seconds