SQL Date comparison problem...

  • Thread starter Thread starter darrel
  • Start date Start date
D

darrel

I'm grabbing today's date with some ASP.net code:

Dim Today As Date
Today = Microsoft.VisualBasic.Today()

I'm then trying to run a SQL query with the following WHERE statement:

WHERE postdate <= " & Today & "

But it's pulling up records that have a postdate in the future.

A sample:

Today (when written to screen) = 3/23/2005 12:00:00 AM
In the SQL table postdate field = 3/28/2005

Anyone see something wrong with what I have that would be causing this? Is
it because in my code I'm grabbing the time, while SQL is only storing the
date?

-Darrel
 
You need to put single quotes around the date.
Otherwise it sees your numbers and slashes as some kind of mathematical
equation.
WHERE postdate <= '" & Today & "'"
 
You need to put single quotes around the date.
Otherwise it sees your numbers and slashes as some kind of mathematical
equation.
WHERE postdate <= '" & Today & "'"

I had tried that as well...same result.

-Darrel
 
It must be your defaul formating on the box running the aspnet code.
Instead of sending it the web server date, send it the db server date
If this is a SQL Server box the SQL syntax is:

"Select * from table Where postdate <=GetDate()"

No single quotes around this function.

Joseph
 
It must be your defaul formating on the box running the aspnet code.
Instead of sending it the web server date, send it the db server date
If this is a SQL Server box the SQL syntax is:

"Select * from table Where postdate <=GetDate()"

That makes a lot more sense. Still, same problem though.

I know have this:

WHERE postdate <= GetDate() AND pulldate > GetDate()

But it's still grabbing records with a postdate field of next monday for
some reason.

-Darrel
 
Back
Top