473,472 Members | 1,800 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Comparing times

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
5 5643
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
"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
Lol,

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

Cor
Nov 21 '05 #4
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Dimension7 | last post by:
All, I am comparing to functions to see which is "better". In better, I mean more efficient, optimize, faster, etc. I have read other posts from other boards, but I'm not really sure of the...
11
by: Dan Stromberg | last post by:
We will soon have 3 copies, for testing purposes, of what should be about 4.5 terrabytes of data. Rather than cmp'ing twice, to verify data integrity, I was thinking we could speed up the...
11
by: Peter | last post by:
Hi how can I compare two byte arrays in VB.NET Thank Peter
4
by: agent349 | last post by:
First off, I know arrays can't be compared directly (ie: if (arrary1 == array2)). However, I've been trying to compare two arrays using pointers with no success. Basically, I want to take three...
41
by: Odd-R. | last post by:
I have to lists, A and B, that may, or may not be equal. If they are not identical, I want the output to be three new lists, X,Y and Z where X has all the elements that are in A, but not in B, and...
8
by: Riegnman | last post by:
Hey guys, I'm in need of a little help. I am very new to access but have been trying to learn. My problem is as follows. . . We have time clocks that dump the badge punches into a .log file on...
2
by: Duppypog | last post by:
I'm trying to compare a date stored in a database with today's date using an If statement, but it's not returning true. Example, value in database is 11/5/2003 with today being 11/6/2003. Can...
5
by: saneman | last post by:
I have a function: int F(double a) { if (a = =1.0) { return 22; } return 44; }
3
by: Brian | last post by:
I need to be able to only allow my clients to enter data into a part of a form between specific hours of the day. i can find tons of articles on comparing dates, but not times. does anyone know...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.