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;
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With