Home  |  Delphi .net Home  |  System.TimeSpan  |  CompareTo Method
  
CompareTo  
Method  
Compares the current TimeSpan value to another
TimeSpan Structure
System NameSpace
CF1.  Function CompareTo ( Target : Object ) : Integer;
CF : Methods with this mark are Compact Framework Compatible
Description
Compares the current (source) time-span value with the Target time-span value. The Target parameter must be a TimeSpan object or a null reference. Quite why this parameter is not TimeSpan is not clear.
 
Returns one of the following values :
 
Source < Target Gives <0
Source = Target Gives  0
Source > Target Gives >0

 
The exact value is not guaranteed.
 
The date and time must be exactly the same to the tick to give a 0 result. (A tick is 0.0000001 seconds).
Microsoft MSDN Links
System
System.TimeSpan
 Author links

 Buy Website Traffic at
 Buywebsitetrafficexperts.com

 Buy Proxies at
 Buyproxies.io
 
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

var
  span1, span2 : TimeSpan;
  result       : Integer;

begin
  span1 := TimeSpan.Create(2, 3, 30);  // 0 days, 2 hours, 3 mins, 30 secs
  span2 := TimeSpan.Create(3, 4, 30);  // 0 days, 3 hours, 4 mins, 30 secs

  result := span1.CompareTo(span2);
  Console.WriteLine('span1 = {0:F}', span1);
  Console.WriteLine('span2 = {0:F}', span2);
  Console.WriteLine('span1 vs span2 = {0}', result.ToString);

  Console.ReadLine;
end.
   span1 = 02:03:30
   span2 = 03:04:30
   span1 vs span2 = -1
 
 
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Contact the author