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

Comparing times

P: n/a
JL
I need to compare two times. The problem I have is this:

In my code I create a time variable using the format statement below:

dim firstTime as DateTime
fistTime = Format("12:00:00 AM", "T")

I then store this in an Access database DateTime field.

When I read it back from the DatTime field. The values do not compare.

When I display the two values using Messagebox.Show, I find that the
variable created with the format statement is in the form:

1/1/001 12:00 AM

and the one read from the Access table is in the form:

12/30/1899 12:00 AM

So my question is how can I format these so I can make a comparison?
Is this a common issue?

TIA,
John
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
John,

For comparing times it is in my opinion the most easy way to compare the
ticks

And to set a time, it gives less problems when you use the ISO time by the
constructor of the datetime (than your program can be used by instance in
Canada as well)

http://msdn.microsoft.com/library/de...sctorTopic.asp

The datetime start in everywhere (technical) else and the way it is stored
as well.

In Net that is (even when it comes from a datetime format in a database)
01 01 01 00 00 00 (international notation) from this point on all dates are
stored in hundred-nanoseconds units from this point

In SQL server at the start of the Georgian Calendar in the Brithis Empire
(somewhere 1853 I thought) from this point on in (AFAIK) milliseconds

And as I see now in Access because you show that at
12/30/1899 12:00 AM

I hope this helps,

Cor

"JL" <jo**@marymonte.com> schreef in bericht
news:qd********************************@4ax.com...
I need to compare two times. The problem I have is this:

In my code I create a time variable using the format statement below:

dim firstTime as DateTime
fistTime = Format("12:00:00 AM", "T")

I then store this in an Access database DateTime field.

When I read it back from the DatTime field. The values do not compare.

When I display the two values using Messagebox.Show, I find that the
variable created with the format statement is in the form:

1/1/001 12:00 AM

and the one read from the Access table is in the form:

12/30/1899 12:00 AM

So my question is how can I format these so I can make a comparison?
Is this a common issue?

TIA,
John

Nov 21 '05 #2

P: n/a
"JL" <jo**@marymonte.com> schrieb:
I need to compare two times. The problem I have is this:

In my code I create a time variable using the format statement below:

dim firstTime as DateTime
fistTime = Format("12:00:00 AM", "T")
I suggest to turn 'Option Strict' on.
I then store this in an Access database DateTime field.

When I read it back from the DatTime field. The values do not compare.

When I display the two values using Messagebox.Show, I find that the
variable created with the format statement is in the form:

1/1/001 12:00 AM

and the one read from the Access table is in the form:

12/30/1899 12:00 AM

So my question is how can I format these so I can make a comparison?


You don't need to convert the resulting 'Date' (= 'DateTime') objects to
strings. The code below shows how to compare 'Date' objects:

\\\
Dim d1 As Date = #12/12/1988 12:23:00 PM#
Dim d2 As Date = #12/12/1988 12:23:00 PM#
Dim d3 As Date = Now
MsgBox(d1 = d2)
MsgBox(d2 = d3)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #3

P: n/a
Lol,

I was already afraid that you had not read my text about it.

Cor
Nov 21 '05 #4

P: n/a
JL
Thank you Cor and Herfried for your responses.

I did not explain correctly that I really only want to compare the
time portion. The dates are added by the system (I guess to complete
the DateTime structure). And since .Net and Access use different dates
for that purpose, I was not getting a correct compare.

What I found that works is to use the TimeValue() function on the
DateTime variables and then the compare correctly. Is there any
problem with that approach?

Thanks again,
John

On Fri, 23 Sep 2005 13:13:20 +0200, "Herfried K. Wagner [MVP]"
<hi***************@gmx.at> wrote:
"JL" <jo**@marymonte.com> schrieb:
I need to compare two times. The problem I have is this:

In my code I create a time variable using the format statement below:

dim firstTime as DateTime
fistTime = Format("12:00:00 AM", "T")


I suggest to turn 'Option Strict' on.
I then store this in an Access database DateTime field.

When I read it back from the DatTime field. The values do not compare.

When I display the two values using Messagebox.Show, I find that the
variable created with the format statement is in the form:

1/1/001 12:00 AM

and the one read from the Access table is in the form:

12/30/1899 12:00 AM

So my question is how can I format these so I can make a comparison?


You don't need to convert the resulting 'Date' (= 'DateTime') objects to
strings. The code below shows how to compare 'Date' objects:

\\\
Dim d1 As Date = #12/12/1988 12:23:00 PM#
Dim d2 As Date = #12/12/1988 12:23:00 PM#
Dim d3 As Date = Now
MsgBox(d1 = d2)
MsgBox(d2 = d3)
///


Nov 21 '05 #5

P: n/a
JL,

I tried to tell you that the used structure should not matter. You cannot
directly compare an access datetime or an SQL server datetime.

You can only compare a Net datetime, that that comes from Access or SQL
server should not be important. (Or the date should be saved in an Access
string value).

However if you are happy with the use of the TimeValue, why than not use it.

It is in my opinion the same as the constructor with

dim dt as time = new datetime(1,1,1,0,0,0)

However, this is what I think that this can helps you as well.

http://msdn.microsoft.com/library/de...classtopic.asp

I hope this helps,

Cor
Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.