# GetFileTime

The GetFileTime function retrieves the date and time that a file was created, last accessed, and last modified.

    BOOL GetFileTime(
      HANDLE hFile,
      CONST FILETIME *lpCreationTime,
      CONST FILETIME *lpLastAccessTime,
      CONST FILETIME *lpLastWriteTime
    );

### Parameters

hFile
Handle to the file for which to get dates and times. The file handle must have been created with the GENERIC_READ access to the file.
lpCreationTime
Pointer to a FILETIME structure to receive the date and time the file was created. This parameter can be NULL if the application does not require this information.
lpLastAccessTime
Pointer to a FILETIME structure to receive the date and time the file was last accessed. The last access time includes the last time the file was written to, read from, or, in the case of executable files, run. This parameter can be NULL if the application does not require this information.
lpLastWriteTime
Pointer to a FILETIME structure to receive the date and time the file was last written to. This parameter can be NULL if the application does not require this information.

### Return value

If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.

### Remarks

The FAT and NTFS file systems support the file creation, last access, and last write time values.

Time precision

- The file time precision can vary depending on operating system, file system, network configuration. See remarks for the FILETIME for details.

Windows NT family

- When Windows NT creates a list of folders (e.g. DIR command) in a NTFS volume, it modifies last access date/time for all found folders. It can degrade effectiveness if the number of folders is very large.
  This behaviour can be controled, see Disable the NTFS Last Access Time Stamp for details.
- If you rename or delete a file, then restore it shortly thereafter, Windows NT searches the cache for file information to restore. Cached information includes its short/long name pair and creation time.

### Example

The following example demonstrates how to retrieve last-write time for a file in string form (Windows NT/2000).

    BOOL GetLastWriteTime(HANDLE hFile, LPSTR lpszString)
    {
      FILETIME ftCreate, ftAccess, ftWrite;
      SYSTEMTIME stUTC, stLocal;

      // get file time and date
      if (!GetFileTime(hFile, &ftCreate, &ftAccess, &ftWrite))
          return FALSE;

      // convert modification time to local time.
      FileTimeToSystemTime(&ftWrite, &stUTC);
      SystemTimeToTzSpecificLocalTime(NULL, &stUTC, &stLocal);

      // convert retrieved time to string
      wsprintf(lpszString, "%02d/%02d/%d  %02d:%02d",
          stLocal.wDay, stLocal.wMonth, stLocal.wYear,
          stLocal.wHour, stLocal.wMinute);

      return TRUE;
    }

See also:
FILETIME, GetFileSize, SetFileTime, GetFileType