Home » RDBMS Server » Server Administration » Help! Where clause using TO_DATE
Help! Where clause using TO_DATE [message #374092] Thu, 24 May 2001 10:54 Go to next message
Mhoward
Messages: 4
Registered: May 2001
Junior Member
I am need of your help. I m using Oracle 8.05 and have a fairly simple query that returns a count of records added on the current date. (adddate field)

So far, the only way I can get it to work is using a date specific clause of:
WHERE adddate >= TO_DATE('24-may-2000','dd-mon-yyyy')

I want to use SYSDATE so that I can use the statement in ASP pages and not have to manually find/replace the hard coded date. However, when I use sysdate in place of the actual date in the TO_DATE conversion, I get different record counts. Why? What should I use to product the same results as hard coding the specific date? I have been working on this one for some time without any success.

Here is the sysdate clause I have attempted to use:
WHERE adddate >= TO_DATE(sysdate,'dd-mon-yyyy')

Any ideas?

Thanks,

Mitch
Re: Help! Where clause using TO_DATE [message #374093 is a reply to message #374092] Thu, 24 May 2001 10:58 Go to previous messageGo to next message
sverch
Messages: 582
Registered: December 2000
Senior Member
What is in your addate?
I mean is it just a SYSDATE? Or TO_DATE(sysdate,'dd-mon-yyyy')?
Re: Help! Where clause using TO_DATE [message #374094 is a reply to message #374092] Thu, 24 May 2001 11:17 Go to previous messageGo to next message
Mhoward
Messages: 4
Registered: May 2001
Junior Member
The field has a datatype of Date. I believe that the application stores the sysdate in this field when the record is added. It is not translated before it is stored.

Thanks,

Mitch
Re: Help! Where clause using TO_DATE [message #374095 is a reply to message #374092] Thu, 24 May 2001 11:19 Go to previous messageGo to next message
Darran
Messages: 2
Registered: May 2001
Junior Member
You shouldn't been using TO_DATE with SYSDATE.
Just use TRUNC to get the date part from SYSDATE (ie removing the time element)

WHERE adddate >= TRUNC(sysdate)
Re: Help! Where clause using TO_DATE [message #374096 is a reply to message #374092] Thu, 24 May 2001 11:21 Go to previous messageGo to next message
Darran
Messages: 2
Registered: May 2001
Junior Member
You shouldn't been using TO_DATE with SYSDATE.
Just use TRUNC to get the date part from SYSDATE (ie removing the time element)

WHERE adddate >= TRUNC(sysdate)
Re: Help! Where clause using TO_DATE [message #374097 is a reply to message #374092] Thu, 24 May 2001 11:23 Go to previous messageGo to next message
Mhoward
Messages: 4
Registered: May 2001
Junior Member
The field has a datatype of Date. I believe that the application stores the sysdate in this field when the record is added. It is not translated before it is stored.

Thanks,

Mitch
Re: Help! Where clause using TO_DATE [message #374100 is a reply to message #374092] Thu, 24 May 2001 13:14 Go to previous messageGo to next message
sverch
Messages: 582
Registered: December 2000
Senior Member
In this case try to convert your adddate:

WHERE TO_DATE(adddate,'DD-MON-YY') >=
TO_DATE(SYSDATE,'dd-mon-yyyy');
Re: Help! Where clause using TO_DATE [message #374101 is a reply to message #374094] Thu, 24 May 2001 13:24 Go to previous messageGo to next message
sverch
Messages: 582
Registered: December 2000
Senior Member
Or just try TRUNC with your SYSDATE
Re: Help! Where clause using TO_DATE [message #374102 is a reply to message #374094] Thu, 24 May 2001 13:27 Go to previous messageGo to next message
sverch
Messages: 582
Registered: December 2000
Senior Member
Or just try TRUNC with your SYSDATE
Re: Help! Where clause using TO_DATE [message #374103 is a reply to message #374095] Thu, 24 May 2001 13:38 Go to previous message
Mhoward
Messages: 4
Registered: May 2001
Junior Member
Thanks a lot for your help on this. That seems to have done the trick!

Thanks,

Mitch
Previous Topic: Japanese string comparison?
Next Topic: Export the result of a query to text file
Goto Forum:
  


Current Time: Wed Jul 03 17:26:17 CDT 2024