SQL Date comparison problem...

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
 
S

Steve C. Orr [MVP, MCSD]

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 & "'"
 
D

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 & "'"

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

-Darrel
 
J

jocoder

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
 
D

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()"

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top