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!

Problems inserting dates into sql string

Status
Not open for further replies.

jfrost10

Programmer
Joined
Jun 3, 2001
Messages
2,004
Location
CA
Hey gang,

I want to return only records that have been entered after the datetime that I'm passing from my asp.net application.
My SQL string I'm passing is this:

"Select Top 15 ChatID, Username, TimeIn, Message From chattable Where ChatID = " & intRoomNum & " And TimeIn >= #" & datTimeIn & "# Order By TimeIn DESC"

The datTimeIn = January 15, 2001 3:44:23 PM
The error I keep getting is that it doesn't like the '3', so the date is fine but not the time. Above I tried using #'s, but i've also tried without them and gotten the same result. Any thoughts?

Thanks,
Jack
 
Try January 15, 2001 03:44:23 PM

Although I usually prefer the following format, it is unambiguous and country independant.

'yyyy-mm-dd hh:mm:ss

And I usually use 24 hour time so what I would pass would be

'2001-01-15 15:44:23'
 
How do I cast the date/time to be a different format (like yyyy-mm-dd hh:mm:ss
?

I've never done that before.

Thanks!

Jack
 
K, I figured out the casting (I think), but how do you cast the am/pm part of it (my system clock needs to be set to standard time, not 24 hours, so I have to include the am/pm)
?

Jack
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top