1. Home
  2. Computing & Technology
  3. Delphi Programming
Glossary|Tips/Tricks|FREE App/VCL|Best'O'Net|Books|Link Back

Delphi Programming RTL Reference|By Category|Alphabetically|By Unit
 

CompareDate

unit
DateUtils
category
date/time routines

declaration
type TValueRelationship = -1..1
function CompareDate(const ADate, BDate: TDateTime) : TValueRelationship

description
Compares two TDateTime values (returns "less", "equal" or "greater"). Ignores the Time part if both values "fall" on the same day.

TValueRelationship represents the relationship between two values. Each of three TValueRelationship values has a "liked" symbolic constant:
-1 [LessThanValue] The first value is less than the second value.
0 [EqualsValue] The two values are equal.
1 [GreaterThanValue] The first value is greater than the second value.

CompareDate results in:

LessThanValue if ADate occurs on a day prior to the Date part of the BDate.
EqualsValue if date parts of both ADate and BDate are the same, ignoring the Time part.
GreaterThanValue if ADate occurs on a day that follows the Date part of the BDate.

example
var  ThisMoment, AnotherMoment : TDateTime;

ThisMoment := Now; 
AnotherMoment := IncADay(ThisMoment, 5); //adds 5 days

//CompareDate(ThisMoment, AnotherMoment) returns LessThanValue (-1)
//CompareDate(AnotherMoment, ThisMoment) returns GreaterThanValue (1)

in real code

see also
CompareTime, CompareDateTime, DateOf, IncADay,


 Free Delphi code snippet inside every Delphi Newsletter!
Subscribe to the Newsletter
Name
Email

 Got some code to share? Got a question? Need some help?
Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming

©2009 About.com, a part of The New York Times Company.

All rights reserved.