Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Compare Date field to today

Status
Not open for further replies.

Kurt111780

Technical User
Joined
Nov 20, 2003
Messages
235
Location
GB
I'm trying to query an access database using C# and ASP.Net. I need to compare the access date field with the current date. This is what I came up with but it does not work.

DateTime dteDate = DateTime.Now;

//query database
objCmd = new OleDbCommand ("SELECT * FROM exhibitions WHERE dteEndDate = " + dteDate + " ORDER BY dteEndDate", objConn);

This is the error message:

Syntax error (missing operator) in query expression 'dteEndDate = 2/18/2005 12:45:44 PM'.

How can I compare a date to todays date?

Thanks,
Kurt
 
I haven't used access for a while but I think it needs a # sign either side of the date.

Also rather than using DateTime.Now use DateTime.Today.ToShortDateString as you don't want to include the time. e.g.
Code:
String strDate = DateTime.Today;

objCmd = new OleDbCommand ("SELECT * FROM MYTABLE WHERE MYDATE = #" & strDate &  "#", objConn);



----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top