Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare two dates of dd/mm/yyyy format?

I have two files and want compare yours compilation dates for a future update.

Suppose that the new file have a date: 20/09/2019, and old file a date: 19/09/2019. How compare these two date on same format (dd/mm/yyyy)?

var
 UpDate, OldDate: string;
begin
  UpDate := '20/09/2019';
  OldDate := DateToStr(FileDateToDateTime(FileAge(IncludeTrailingBackslash(ExtractFilePath(Application.ExeName)) + 'test.exe'))) // 19/09/2019

  if UpDate > OldDate then
  begin
    // Do something
  end;
end;
like image 388
FLASHCODER Avatar asked Oct 16 '25 14:10

FLASHCODER


1 Answers

Instead of manipulating strings, you can deal directly with TDateTime values by invoking DateUtils.CompareDate().

var  OldDate, UpDate : TDateTime;
begin
  OldDate := EncodeDate(2019, 9, 20);
  UpDate := FileDateToDateTime(FileAge(IncludeTrailingBackslash(ExtractFilePath(Application.ExeName)) + 'test.exe'));
  if CompareDate(OldDate, UpDate) = LessThanValue  Then
  begin
    // Do something
  end;
end;
like image 90
Amessihel Avatar answered Oct 18 '25 12:10

Amessihel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!