# Function Reference

# _Date_Time_SetFileTime

Sets the date and time that a file was created, accessed and modified

#include <Date.au3>
_Date_Time_SetFileTime ( $hFile, $tCreateTime, $tLastAccess, $tLastWrite )

## Parameters

$hFile | Handle to the file. The file handle must have been created using the CreateFile function with the FILE_WRITE_ATTRIBUTES access right.
$tCreateTime | a $tagFILETIME structure that contains the new date and time the file was created. This be 0 if the application does not need to set this information.
$tLastAccess | a $tagFILETIME structure that contains the new 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 can be 0 if the application does not need to set this information. To preserve the existing last access time for a file even after accessing a file, call SetFileTime with this parameter set to -1 before closing the file handle.
$tLastWrite | a $tagFILETIME structure that contains the new date and time the file was last written to. This can be 0 if the application does not want to set this information.

## Return Value

Success: | True
Failure: | False

## Remarks

Not all file systems can record creation and last access times and not all file systems record them in the same manner.
For example, on FAT, create time has a resolution of 10 milliseconds, write time has a resolution of 2 seconds, and access time has a resolution of 1 day (really, the access date). Therefore, the _Date_Time_GetFileTime() function may not return the same file time information set using _Date_Time_SetFileTime().
NTFS delays updates to the last access time for a file by up to one hour after the last access.

## Related

$tagFILETIME, _Date_Time_GetFileTime

## Example

    #include "Extras\HelpFileInternals.au3"

    #include <Date.au3>
    #include <GUIConstantsEx.au3>
    #include <WinAPIError.au3>
    #include <WinAPIFiles.au3>
    #include <WinAPIHObj.au3>
    #include <WindowsStylesConstants.au3>

    Example()

    Func Example()
        Local $hFile, $tFile, $aTime
        Local $sTempFile = @TempDir & "\Test.xyz"

        ; Create GUI
        GUICreate("Time", 400, 300)
        _MemoCreate(2, 2, 396, 296, $WS_VSCROLL)
        GUISetState(@SW_SHOW)

        ; Create test file and set file times
        $hFile = _WinAPI_CreateFile($sTempFile, 1)
        If $hFile = 0 Then _WinAPI_ShowError("Unable to create file")
        $tFile = _Date_Time_EncodeFileTime(@MON, @MDAY, @YEAR, @HOUR, @MIN, @SEC)
        _Date_Time_SetFileTime($hFile, $tFile, $tFile, $tFile)
        _WinAPI_CloseHandle($hFile)

        ; Read file times
        $hFile = _WinAPI_CreateFile($sTempFile, 2)
        If $hFile = 0 Then _WinAPI_ShowError("Unable to open file")
        $aTime = _Date_Time_GetFileTime($hFile)
        _WinAPI_CloseHandle($hFile)

        _MemoWrite("Created ..: " & _Date_Time_FileTimeToStr($aTime[0]))
        _MemoWrite("Accessed .: " & _Date_Time_FileTimeToStr($aTime[1]))
        _MemoWrite("Modified .: " & _Date_Time_FileTimeToStr($aTime[2]))

        ; Loop until the user exits.
        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE

        FileDelete($sTempFile)
    EndFunc   ;==>Example