Access datetime format problem?

J

John Dann

I'm generating 2 datetime values inside a VB.Net program say datetime1
and datetime2.

datetime1 is retrieved from an Access database from a column of
datetime type.

datetime2 is generated internally by the program.

I want to test the condition:

If datetime1=datetime2 then CodeBlock

But CodeBlock never seems to get called even when I'm sure that
datetime1 and datetime2 are identical.

If I look at the identical datetime1/2 values I do see a difference in
formatting in the time part:

datetime1 (from Access) shows time as eg 11:59:59 PM

datetime1 (internally set) shows time as eg 23:59:59

Question is: Am I trying to test identity of the datetime values in
the wrong way or is the problem the difference in time formatting? If
the latter then is there some way I can set the database to return
datetime values using 24 hour clock times?

TIA
JGD
 
J

Jon Skeet [C# MVP]

John Dann said:
I'm generating 2 datetime values inside a VB.Net program say datetime1
and datetime2.

datetime1 is retrieved from an Access database from a column of
datetime type.

datetime2 is generated internally by the program.

I want to test the condition:

If datetime1=datetime2 then CodeBlock

But CodeBlock never seems to get called even when I'm sure that
datetime1 and datetime2 are identical.

If I look at the identical datetime1/2 values I do see a difference in
formatting in the time part:

datetime1 (from Access) shows time as eg 11:59:59 PM

datetime1 (internally set) shows time as eg 23:59:59

Question is: Am I trying to test identity of the datetime values in
the wrong way or is the problem the difference in time formatting? If
the latter then is there some way I can set the database to return
datetime values using 24 hour clock times?

Formatting should make no difference here. The DateTime itself has no
formatting information associated with it.

What I suspect you're seeing is an inaccuracy in the DateTime stored in
Access. I suggest you print the Ticks property of each DateTime - I
suspect you'll find they're slightly different.
 

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