By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,911 Members | 1,147 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,911 IT Pros & Developers. It's quick & easy.

problem with comparing date

P: n/a
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

Dec 14 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

Bob wrote:
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
Dec 14 '06 #2

P: n/a
Bob
Thanks both
"Andrew Backer" <aw******@gmail.comschreef in bericht
news:11*********************@n67g2000cwd.googlegro ups.com...
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

Bob wrote:
>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

Dec 14 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.