Thread: How do you compare date values
08-02-04, 12:17 #1Registered User
- Join Date
- Aug 2004
Unanswered: How do you compare date values
I'm stuck trying to compare date values from users selection against a database. I also need to add a condition statement on if the results return no match. How would I do that?
Also, I'm not even sure if my SELECT statement is right. The user will hit a date that will be in format m/d/yyyy and that will be compared to see if it exist in the database. The datebase column "date_created" is default with date/time( 8 ). But when I compare the to together, nothing returns back. The page loads successfully, but no results from the database.
Here is my code:
dim conpubs as sqlconnection
dim cmdSelectAuthors as sqlcommand
dim dtrAuthors As sqlreader
conpubs = New sqlconnection(configurationsettings.appSettings("S TD"))
cmdSelectAuthors = New sqlcommand("Select * From HotNews WHERE date_created=" & y, conpubs)
dtrAuthors = cmdSelectAuthors.ExecuteReader()
Response.Write(dtrAuthors("title") & "<br>")
08-02-04, 12:26 #2Registered User
- Join Date
- Jul 2003
- San Antonio, TX
I assume your "y" variable contains the date and date_created contains time values other than midnight.
cmdSelectAuthors = New sqlcommand("Select * From HotNews WHERE date_created between '" & y & "' and dateadd(ms, -10, dateadd(day, 1, '" & y & "'))", conpubs)"The data in a record depends on the Key to the record, the Whole Key, and
nothing but the Key, so help me Codd."