Oracle DB Query | where date greater than or equal to

gduron

Board Regular
Joined
Mar 27, 2006
Messages
94
Hello All,

I have a table that is located in an oracle database. The table has a number of columns. I'm able to successfully connect to the database and query without any problems as long as I do not try to filter on a date column. But as soon as I try to say "where date >= '1/1/2010' (date can be anyting), the record set is empty. I know there should be records returned, but for some reason my date query is not working.

Any ideas would be greatly appreciated.

Example 1 (works no problem):
Code:
str_sql = "select * from table"
rs.Open str_sql, con

Example 2 (returns empty recordset):
Code:
str_sql = "select * from table where startdate>='1/1/2010'"
rs.Open str_sql, con

One final thing is when I look at the properties of this column, the defined size is "16"

Thanks in advance.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Are you sure it's not defined as a date-time?
such that you may need to convert your parameter to date-time to get accurate an return.
 
Upvote 0
Of course, I spend two days looking for a solution and then I find one that works right after I post on this site. :)


I'm not sure why this works, but apparently there is a function that helps define the type in the query for Oracle called "to_date".

If anyone has any idea of why this function is necessary, I'd appreciate it.

Code:
str_sql = "select * from table where startdate>=to_date('1/1/2010','mm/dd/yyyy')"
rs.Open str_sql, con
 
Upvote 0
The field is defined as a date-time stamp. Handing string parameters to compare against dates doesn't generally work because dates are generally stored as floating point numeric values. Trying to use an air filter on the oil pump, so to speak.
 
Upvote 0
So if I understand correctly, the to_date function actually converts the string '1/1/2010' to a the numeric equivalent that the date is actually stored as?
 
Upvote 0
Yep!

Though I've seen data definitions differ in the same database, by the same vendor.
Sometimes they can be date-time, sometimes as various string patterns. yyyy-mm-dd, cyymmdd, etc.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,030
Messages
6,122,762
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top