1. Home
  2. Computing & Technology
  3. Delphi Programming

Converting from TFileTime to TDateTime

By Zarko Gajic, About.com

The FindData field of TSearchRec (the record used by FindFirst and FindNext to retrieve directory entries) is another record that among other information (like for example the short and long names of the file) has three fields that represent the creation, last access and last write times (ftCreationTime, ftLastAccessTime, ftLastWriteTime respectively). These three fields are declared as TFileTime, a type that represents 64-bit dates in Coordinated Universal Time (UTC).

If you want to convert these values to TDateTime, you can use the following function:

~~~~~~~~~~~~~~~~~~~~~~~~~
uses Windows;

function FileTime2DateTime
   (FileTime: TFileTime): TDateTime;
var
   LocalFileTime: TFileTime;
   SystemTime: TSystemTime;
begin
   FileTimeToLocalFileTime(FileTime, LocalFileTime) ;
   FileTimeToSystemTime(LocalFileTime, SystemTime) ;
   Result := SystemTimeToDateTime(SystemTime) ;
end;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» Flicker free TImage in Delphi
« Stop Windows from Displaying Critical Error Messages

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2002 Delphi Tips
  7. Converting from TFileTime to TDateTime

©2009 About.com, a part of The New York Times Company.

All rights reserved.