Compare datetime in milliseconds

M

Mark

I'd like to compare two datetime values in milliseconds. The
datetime.compare method appears to show only seconds. Milliseconds of a
datetime are available as a property of each datetime, but I am assuming
there is an easier way than comparing the milliseconds, seconds, minutes,
hours, days, etc, individually to generate the difference.

Thanks in advance.

Mark
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Mark said:
I'd like to compare two datetime values in milliseconds. The
datetime.compare method appears to show only seconds. Milliseconds of a
datetime are available as a property of each datetime, but I am assuming
there is an easier way than comparing the milliseconds, seconds, minutes,
hours, days, etc, individually to generate the difference.

DateTime Compare returns negative, zero, positive.

If you simply subtract the two DateTime then you get a
TimeSpan where you can use the TotalMilliSeconds property.

Arne
 
C

Carl Daniel [VC++ MVP]

Mark said:
I'd like to compare two datetime values in milliseconds. The
datetime.compare method appears to show only seconds. Milliseconds
of a datetime are available as a property of each datetime, but I am
assuming there is an easier way than comparing the milliseconds,
seconds, minutes, hours, days, etc, individually to generate the
difference.

Someone (possibly yourself) has led you astray about DateTime.Compare.

The DateTime struct is nothing but a fancy wrapper around the DateTime.Ticks
property - all other units are synthesized via simple algebraic
relationships (60 seconds in a minute, and so on).

DateTime.Compare compares the Ticks value, so there is no higher precision
comparison possible between DateTime objects than that provided by
DateTime.Compare.

-cd
 
W

Walter Wang [MSFT]

Hi Mark,

Just in case you wonder what is Tick: a tick is the smallest unit of time
that can be specified. One millisecond = 10000 ticks. You can use the
TimeSpan.TotalMilliseconds to get the difference between two DateTime just
as Arne described.


Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

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