What is the correct format for DateTime.Compare ?

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,
 
S

samoore33

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
 
S

samoore33

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
 
M

Mudhead

How are you going to guarantee that DateTime.Now and your curDteTime will
ever be equal?
 
S

Smokey Grindle

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
 
J

Jay B. Harlow [MVP - Outlook]

| 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
 
C

Cor Ligthert [MVP]

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
 

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