What is the correct format for DateTime.Compare ?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi;

What is the correct format for the method DateTime.Compare ?

I can't get this to work -

Dim currDteTime as DateTime = #08/15/2006 02:45:00 PM#

If DateTime.Compare(DateTime.Now, currDteTime) = 0 then
myNextSub()
End If

What am I doing wrong ?

Thanks,
 
Gordon,

Is it because of the zero before the 8. Instead of #08/15/2006 02:45:00
PM#, try #8/15/2006 02:45:00 PM#. Not sure but I had a problem with
that before.

Scott
 
Gordon,

Is it because of the zero before the 8. Instead of #08/15/2006 02:45:00
PM#, try #8/15/2006 02:45:00 PM#. Not sure but I had a problem with
that before.

Scott
 
How are you going to guarantee that DateTime.Now and your curDteTime will
ever be equal?
 
The datetime.compare is done within a loop. And curDteTime will occur in the
future
 
do a parse instead....

dim currDteTime as DateTime = DateTime.Parse("8/15/2006 2:45:00 PM")

its more .NET like then the old VB ## method
 
| What am I doing wrong ?
You only gave hours & minutes on your time, datetime.now also includes
seconds, milliseconds & fractions of milliseconds:

currDteTime: 8/15/2006 2:45:00 PM
DateTime.Now: 8/15/2006 5:53:57 PM

Generally its safer to compare times either less or greater; something like:

| If DateTime.Compare(DateTime.Now, currDteTime) <= 0 then
| myNextSub()
| End If

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| Hi;
|
| What is the correct format for the method DateTime.Compare ?
|
| I can't get this to work -
|
| Dim currDteTime as DateTime = #08/15/2006 02:45:00 PM#
|
| If DateTime.Compare(DateTime.Now, currDteTime) = 0 then
| myNextSub()
| End If
|
| What am I doing wrong ?
|
| Thanks,
| --
| Gordon
 
Smokey,
dim currDteTime as DateTime = DateTime.Parse("8/15/2006 2:45:00 PM")

its more .NET like then the old VB ## method
On what is that statement based?

dim currDteTime as DateTime = new DateTime(2006, 8, 14,45,00)

Is in my idea more correct and also in standard ISO globalized format . The
by you used format is only good in the USA and Coca Cola cultures, not even
in English speaking Canada.

Cor
 
Gordon,

In addition to Jay,

Decide what datepart you want to compare.
The current as you have used has in my idea a low hit change because the
datetime structure retuns dates which are a kind of secure in 100th of a
nanosecond.

I would probably do it with an ANDALSO with the date and TimeOfDay member
from DateTime.

http://msdn2.microsoft.com/en-us/library/system.datetime_members.aspx

I hope this helps,

Cor
 

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

Back
Top