Author: Tomas Rutkauskas
How to capture the date and time stamp of a file
Would you like to display a file's date and/or time stamp to your user? There isn't
a single Delphi function that does this on its own. However, we can combine two
functions to get the results we want. First, the FileGetDate function returns the
DOS date-time stamp of the file specified by its handle, Fhandle. Then, the
FileDateToDateTime function translates the integer into a TDateTime value. Finally,
the DateTimeToStr procedure converts the TDateTime value into a string.
1 procedure TForm1.Button1
2 var3 TheFileDate: string;
4 FHandle: integer;
5 begin6 FHandle := FileOpen(YourFileName, 0);
7 try8 TheFileDate := DateTimeToStr(FileDateToDateTime(FileGetDate(FHandle)));
9 finally10 FileClose(FHandle);
Use formatting parameters DateTimeToStr to refine the output. Even if you don't have to display the time and date, you can use this technique to perform comparisons and calculations on file dates.