|
Technical answers from the trenches |
|
Determining Oldest or Latest Date Values
| ||||
Posted: 1 April 2002 |
||||
  |
Applies to: All versions |
|||
  |
Audience: Intermediate |
|||
Question: How can I quickly determine the first or last date from a set of TDateTime (or TDate) values?Answer: Use functions provided in the MATH unit, as shown in the following code sample: procedure TForm1.Button2Click(Sender: TObject);
var
dtIn1, dtIn2, dtIn3, dtOut : TDateTime;
begin
dtIn1 := strToDateTime( '1/1/80' );
dtIn2 := strToDateTime( '6/21/97' );
dtIn3 := strToDatetime( '12/31/63' );
dtOut := minValue( [ dtIn1, dtIn2, dtIn3 ] );
inputBox( 'Oldest Date', 'The earliest date: ',
DateTimeToStr( dtOut ) );
end;This works because TDateTime and TDate values are internally represented as floating point values, thus you can use the floating point comparison functions in the MATH unit. Here's a quick list of the functions you can use:
This can save quite a bit of development and testing time, depending on the number of date values being compared. (Don't forget to add the MATH unit to an appropriate USES block.) For more information, search the Visual Component Reference Help file for "Statistical routines." |
|||||||||||||
|
||||||||
|
Copyright © 2000-2004, techtricks.com; All Rights Reserved. Acknowledgements, Disclaimers, Terms and Conditions. |
||||||||
|
Article last updated on 31 May 2003
|
||
|
|
||
|
[- End -]
|