Home All Groups Group Topic Archive Search About

problem with comparing date

Author
14 Dec 2006 6:00 PM
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

Author
14 Dec 2006 6:28 PM
Kerry Moorman
Bob,

Perhaps you just want to compare the date portion of the datetime variables?

If you get the 2 values into 2 variables, d1 and d2, both of type DateTime,
you can compare the date portion like this:

If d1.Date > d2.Date Then ...

Kerry Moorman


Show quoteHide quote
"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
>
>
>
>
>
>
Author
14 Dec 2006 6:34 PM
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

Bob wrote:
Show quoteHide quote
> 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
Author
14 Dec 2006 7:37 PM
Bob
Thanks both


Show quoteHide quote
"Andrew Backer" <awbac***@gmail.com> schreef in bericht
news:1166121254.790322.72880@n67g2000cwd.googlegroups.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
>