PC Review


Reply
Thread Tools Rate Thread

Compare datetime in milliseconds

 
 
Mark
Guest
Posts: n/a
 
      26th Aug 2006
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


 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?Arne_Vajh=F8j?=
Guest
Posts: n/a
 
      26th Aug 2006
Mark wrote:
> 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
 
Reply With Quote
 
Carl Daniel [VC++ MVP]
Guest
Posts: n/a
 
      26th Aug 2006
Mark wrote:
> 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


 
Reply With Quote
 
Walter Wang [MSFT]
Guest
Posts: n/a
 
      28th Aug 2006
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 ((E-Mail Removed), 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting the datetime with milliseconds value into a datarow Manikandan Microsoft C# .NET 6 9th Jul 2007 11:29 PM
how to get the number of milliseconds between two System.DateTime objects Daniel Microsoft Dot NET 2 20th Sep 2005 05:26 PM
Can't populate SQLServer datetime column with milliseconds Joe Rattz Microsoft ADO .NET 3 13th May 2004 01:49 PM
RE: Bug with SQLServer datetime fields and milliseconds Kevin Yu [MSFT] Microsoft ADO .NET 1 13th May 2004 01:33 PM
Inserting C# datetime milliseconds into sql Server DateTime tk042383 Microsoft ADO .NET 2 4th May 2004 04:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:35 PM.