FileTimeToSystemTime Function

Declare Function FileTimeToSystemTime Lib "kernel32.dll" (lpFileTime As FILETIME, lpSystemTime As SYSTEMTIME) As Long

Platforms: Win 32s, Win 95/98, Win NT

FileTimeToSystemTime converts a time and date stored in a FILETIME structure to an identical time and date stored in a SYSTEMTIME structure. The latter structure provides a easier way to access a date and time, whereas the former is used by Windows to identify times and dates associated with files. The data put into the SYSTEMTIME structure identifies the same time and date as the source structure does. The function returns 0 if an error occured, or 1 if successful.

lpFileTime
The date and time, in FILETIME form, to convert.
lpSystemTime
Receives the date and time converted into SYSTEMTIME format.

Example:

' Display the date when file C:\MyProgram\datafile.txt was
' created.  Note how CreateFile's alternate declare must be used under Win 95/98 --
' see that function's page for more information.  Also note how the times returned by GetFileTime
' need to be converted so the program can figure out what the date actually is.
Dim hfile As Long  ' receives the handle to the file
Dim ctime As FILETIME  ' receives creation date and time of the file
Dim atime As FILETIME  ' receives last access date and time of the file
Dim wtime As FILETIME  ' receives last write-to date and time of the file
Dim createtime As SYSTEMTIME  ' receives a converted form of ctime
Dim retval As Long  ' return value

' Get a handle to the file (note how the alternate declare is used):
hfile = CreateFileNS("C:\MyProgram\datafile.txt", GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_ARCHIVE, 0)
If hfile = -1 Then  ' if the file could not be opened
  Debug.Print "Could not open the file C:\MyProgram\datafile.txt."
  End  ' abort the program
End If

' Get the various times and dates associated with the file:
retval = GetFileTime(hfile, ctime, atime, wtime)
' Convert the creation time from a FILETIME structure to a SYSTEMTIME structure (for usability):
retval = FileTimeToSystemTime(ctime, createtime)
' Display the creation date of the file:
Debug.Print "Creation Date:"; createtime.wMonth; "-"; createtime.wDay; "-"; createtime.wYear

' Close the file
retval = CloseHandle(hfile)

See Also: SystemTimeToFileTime
Category: Time

Go back to the alphabetical Function listing.
Go back to the Reference section index.


This page is copyright © 2000 Paul Kuliniewicz. Copyright Information.
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/f/filetimetosystemtime.html