0

I want to extract data from database where field "end_ date" is less than today's date and where end_date is not equal to null; how would I do that? I figured the second part out .. I have trouble with first part

select * 
 from table 
where to_char(end_date) IS NOT null
1
  • 2
    You don't need to waste time converting the end date to a string to test it for null-ness; just use "WHERE end_date IS NOT NULL". Commented Oct 19, 2009 at 14:57

4 Answers 4

7

Try this

   ... 
   Where end_ date is not null and 
      And end_date < sysdate

And, actually, I think you may not even need the first part, as if end_date is null, it certainly will not be after todays date, so try this by itself:

Where end_date < sysdate

EDIT NOTEs:

  1. This will give you every record that has an end_date prior to the current system date and time, including those with end_Date values earlier today. If you want only those with end_Dates up to and not including midnight last night, then you need to replace "sysDate" with an expression for the date time value for midnight last night..

    Where end_date < trunc(sysdate)

  2. sysdate is oracle specific syntax to return the current system date and time. (in SQL Server, for e.g., it's a function called getDate() . The ANSI-Standard Syntax for this functionality, (which works in both Oracle and SQL Server, and should work in any ANSI-standard database) is CURRENT_TIMESTAMP.

Sign up to request clarification or add additional context in comments.

2 Comments

+1: you don't need the "not null" part (since a NULL date would not be "less than sysdate")
Great explanation tnx a bunch
0
select * from table where end_date < CURRENT_DATE and end_date IS NOT null

Comments

0

To show you a little more on how to use the Dates in Oracle check this out:

Selects the current date and removes 30 minutes from it where check_date is declared as a timestamp.

select current_timestamp + interval '-30' minute into check_date from dual;

Selects everything from table where end_date is not null and above now - 30 minutes

select * from table
where to_char(end_date) is not null and end_date < check_date;

Comments

0

select * from table where to_char(end_date,'DD-MM-YYYY') is not null and end_date < sysdate;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.