Compare datetime in milliseconds

  • Thread starter Thread starter Mark
  • Start date Start date
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
 
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
 
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
 
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.
 
Back
Top