problem with comparing date

B

Bob

Hi,

I have a wrong result when testing today against a date fetched from a table
in excel.
The value in excel is: 14/12/2006 (european format).
When today is after that value in excel, the message "time is over" must
appear, otherwise nothing.

My problem is that the message appear already when today = that value.
Any idea why?

When doing response.write(n & " " & dtreader.GetDateTime(0)), i get:
14/12/2006 18:57:23 14/12/2006

Thanks
Bob


Dim n As Date
n = Date.Now
......
sql = "select mydate from mytable;"
comd = New OleDbCommand(sql, oConnection)
dtreader = comd.ExecuteReader
dtreader.Read()
.....
If n > dtreader.GetDateTime(0) Then
response.write("time is over")
end if
 
A

Andrew Backer

Just a thought, but "today at 6:57pm is > today at 12:00 am" looks like
what you have there. If there is no time shown it generally means that
the time is the 0s when comparing against something with a time
component.

Try using Date.Today or DateTime.Today to get a "Date" value and not a
"DateTime".

After that it would probably be a good idea to strip of the time from
the DataReader value by calling dtreader.GetDateTime(0).Date to get the
date portion only.

HTH,
Andrew
 
B

Bob

Thanks both


Andrew Backer said:
Just a thought, but "today at 6:57pm is > today at 12:00 am" looks like
what you have there. If there is no time shown it generally means that
the time is the 0s when comparing against something with a time
component.

Try using Date.Today or DateTime.Today to get a "Date" value and not a
"DateTime".

After that it would probably be a good idea to strip of the time from
the DataReader value by calling dtreader.GetDateTime(0).Date to get the
date portion only.

HTH,
Andrew
 

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

Top