ObjectPascal
DateTimeToFileDate
Function
Convert a TDateTime value to a File date/time format SysUtils unit
 function DateTimeToFileDate ( DateTime : TDateTime ) : Integer;
Description
The DateTimeToFileDate function converts a TDateTime value DateTime to the format used for file dates.
 
The file date is more restricted in range than TDateTime : Year must be 1980 .. 2099 Milli-seconds are rounded to 2 decimal places
Related commands
FileAge Get the last modified date/time of a file without opening it
FileDateToDateTime Converts a file date/time format to a TDateTime value
FileSetDate Set the last modified date and time of a file
 
Example code : Display, update, and redisplay the last modified date of a file
var
  fileName    : string;
  fileDate    : Integer;
  newDateTime : TDateTime;

begin
  // Try to open the Unit1.DCU file for the current project
  fileName := 'Unit1.DCU';
  fileDate := FileAge(fileName);

  // Did we get the file age OK?
  if fileDate > -1 then
  begin
    ShowMessage(fileName+' last modified date = '+
                DateTimeToStr(FileDateToDateTime(fileDate)));

    // Now change the last modified date
    newDateTime := StrToDateTime('01/01/2000 12:34:56');
    FileSetDate(fileName, DateTimeToFileDate(newDateTime));
  end;

  // Did we update the file last modified date OK?
  fileDate := FileAge(fileName);
  if fileDate > -1 then
    ShowMessage(fileName+' last modified date = '+
                DateTimeToStr(FileDateToDateTime(fileDate)));
end;
Show full unit code
   Unit1.DCU last modified date = 30/10/2002 15:16:22
   Unit1.DCU last modified date = 01/01/2000 12:34:56