Home All Groups Group Topic Archive Search About

What is the correct format for DateTime.Compare ?

Author
15 Aug 2006 7:36 PM
Gordon
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

Author
15 Aug 2006 7:48 PM
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

Gordon wrote:
Show quoteHide quote
> 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
Author
15 Aug 2006 7:49 PM
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

Gordon wrote:
Show quoteHide quote
> 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
Author
15 Aug 2006 8:01 PM
Mudhead
How are you going to guarantee that DateTime.Now and your curDteTime will
ever be equal?


Show quoteHide quote
"Gordon" <Gor***@discussions.microsoft.com> wrote in message
news:EB5E85D5-12DE-4455-B6FC-977DE817A445@microsoft.com...
> 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
Author
15 Aug 2006 8:15 PM
Gordon
The datetime.compare is done within a loop. And curDteTime will occur in the
future
--
Gordon


Show quoteHide quote
"Mudhead" wrote:

> How are you going to guarantee that DateTime.Now and your curDteTime will
> ever be equal?
>
>
> "Gordon" <Gor***@discussions.microsoft.com> wrote in message
> news:EB5E85D5-12DE-4455-B6FC-977DE817A445@microsoft.com...
> > 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
>
>
>
Author
15 Aug 2006 8:31 PM
Mudhead
I think you should read the Polling For Time article here:
http://www.flounder.com/badprogram.htm#SleepEx.

Show quoteHide quote
"Gordon" <Gor***@discussions.microsoft.com> wrote in message
news:05216D44-4B69-4742-8C90-819880720D52@microsoft.com...
> The datetime.compare is done within a loop. And curDteTime will occur in
> the
> future
> --
> Gordon
>
>
> "Mudhead" wrote:
>
>> How are you going to guarantee that DateTime.Now and your curDteTime will
>> ever be equal?
>>
>>
>> "Gordon" <Gor***@discussions.microsoft.com> wrote in message
>> news:EB5E85D5-12DE-4455-B6FC-977DE817A445@microsoft.com...
>> > 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
>>
>>
>>
Author
16 Aug 2006 10:01 AM
Larry Lard
Mudhead wrote:
> I think you should read the Polling For Time article here:
> http://www.flounder.com/badprogram.htm#SleepEx.

Great page!

--
Larry Lard
larryl***@googlemail.com
The address is real, but unread - please reply to the group
For VB and C# questions - tell us which version
Author
15 Aug 2006 8:15 PM
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


Show quoteHide quote
"Gordon" <Gor***@discussions.microsoft.com> wrote in message
news:EB5E85D5-12DE-4455-B6FC-977DE817A445@microsoft.com...
> 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
Author
16 Aug 2006 6:41 AM
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
Author
15 Aug 2006 11:37 PM
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


Show quoteHide quote
"Gordon" <Gor***@discussions.microsoft.com> wrote in message
news:EB5E85D5-12DE-4455-B6FC-977DE817A445@microsoft.com...
| 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
Author
16 Aug 2006 6:52 AM
Cor Ligthert [MVP]
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


Show quoteHide quote
"Gordon" <Gor***@discussions.microsoft.com> schreef in bericht
news:EB5E85D5-12DE-4455-B6FC-977DE817A445@microsoft.com...
> 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