As quoted in the Heber answer you can compare dates through operators >
and <
plus =
to check if they match.
Var
DataAtual, DataVencimento: String;
Begin
DataAtual := FormatDateTime('dd/mm/yyyy', Date);
DataVencimento := '20/02/2014';
If (DataVencimento = DataAtual) then
ShowMessage('A Data atual coincide com a Data de Vencimento!')
Else If (DataVencimento > DataAtual) then
ShowMessage('A Data Atual é superior a Data de Vencimento!')
Else If DataVencimento < DataAtual then
ShowMessage('A Data Atual é inferior a Data de Vencimento!')
End;
If you prefer, there is also a library that provides some functions that allow you to work with dates / times more precisely, at DateUtils
.
Examples
To compare the difference between two dates, use the CompareDate
function:
Var
DataAtual, DataVencimento: TDate;
Value: Integer;
Begin
DataAtual := StrToDate(FormatDateTime('dd/mm/yyyy', Now));
DataVencimento := StrToDate('20/02/2014');
Value := CompareDate(DataAtual, DataVencimento);
If Value = 0 then
MessageDlg('A Data Atual coincide com a Data de Vencimento!', mtInformation, [mbOK], 0)
Else If Value = 1 then
MessageDlg('A Data Atual é superior a Data de Vencimento!', mtInformation, [mbOK], 0)
Else
MessageDlg('A Data Atual é inferior a Data de Vencimento!', mtInformation, [mbOK], 0);
End;
To know the difference of days between two dates, use the DaysBetween
function. :
Var
DataAtual, DataVencimento: TDate;
Diff: String;
Begin
DataAtual := StrToDate(FormatDateTime('dd/mm/yyyy', Now));
DataVencimento := StrToDate('20/02/2014');
Diff := FloatToStr(DaysBetween(DataAtual, DataVencimento));
MessageDlg(Format('A diferença entre %s e %s é de %s dias',
[DateToStr(DataAtual), DateToStr(DataVencimento), Diff]),
mtInformation, [mbOK], 0);
End;
For the difference of weeks between two dates, use the WeeksBetween
function. :
Var
DataAtual, DataVencimento: TDate;
Diff: String;
Begin
DataAtual := StrToDate(FormatDateTime('dd/mm/yyyy', Now));
DataVencimento := StrToDate('20/02/2014');
Diff := FloatToStr(WeeksBetween(DataAtual, DataVencimento));
MessageDlg(Format('A diferença entre %s e %s é de %s semanas',
[DateToStr(DataAtual), DateToStr(DataVencimento), Diff]),
mtInformation, [mbOK], 0);
End;
For the difference of months between dates use the MonthsBetween
function, for years use YearsBetween
.
Related : Firebird Dates Calculation