From: pandeng@telepath.com (Steve Schafer (TeamB)) Subject: Re: TFileTime to TDateTime conversion Date: 05 Oct 1999 00:00:00 GMT Message-ID: <380528ba.308657407@90.0.0.40> Content-Transfer-Encoding: 7bit References: <7tcnnk$7a44@forums.borland.com> Content-Type: text/plain; charset=us-ascii Organization: TeamB Mime-Version: 1.0 Reply-To: pandeng@telepath.com Newsgroups: borland.public.delphi.winapi On Tue, 5 Oct 1999 13:39:03 +0200, "Romain Petges" wrote: >does anybody know how I can convert a TFileTime type to TDateTime. >TFileTime is used by many Win32 API functions. There are a couple of straightforward ways to do it; both of them are somewhat convoluted. The conceptually simplest way is to use FileTimeToSystemTime to reformat the time into a SYSTEMTIME structure, and then use EncodeDate and EncodeTime to convert the resulting fields to TDateTime. The quicker way is to use FileTimeToDosDateTime to convert the time to DOS date/time format, combine the two resulting fields into a LongInt (with the date in the upper half), and then pass the result to FileDateToDateTime. But the best way of all is to realize that TFileTime and TDateTime are both linear representations of time, albeit with different rates and start points. Therefore, you can do a simple affine transformation to convert one to the other: function Win32FileTimeToDateTime(Time: TFileTime): TDateTime; begin Result := (Time.dwLowDateTime / 86400.0E7) + (Time.dwHighDateTime * 65536.0 * 65536.0 / 86400.0E7) - 109205 end; Note that no matter which method you use, TFileTime stores its values as UTC, so you'll have to add or subtract an appropriate number of hours to convert to local time. -Steve