How do I programmatically change the create, modify, access date on a file?

Using PowerShell, the command would be:

PS C:\temp> (Get-Item Notes.txt).lastwritetime=$(Get-Date "1/2/2016 12:34 am")

PS C:\temp> (Get-Item Notes.txt).creationtime=$(Get-Date "1/2/2016 12:34 am")

PS C:\temp> (Get-Item Notes.txt).lastaccesstime=$(Get-Date "1/2/2016 12:34 am")

Enter image description here


Here is a VBScript example of changing the modification date:

Sub ChangeModifiedDate(strFolder, strFile, dteNew)

    Dim oShell
    Dim objFolder

    Set oShell = CreateObject("Shell.Application")
    Set oFolder = oShell.NameSpace(strFolder)
    oFolder.Items.Item(strFile).ModifyDate = dteNew
End Sub

If you have PowerShell:

$(Get-Item ).creationtime=$(Get-Date "mm/dd/yyyy hh:mm am/pm")
$(Get-Item ).lastaccesstime=$(Get-Date "mm/dd/yyyy hh:mm am/pm")
$(Get-Item ).lastwritetime=$(Get-Date "mm/dd/yyyy hh:mm am/pm")

Note that the correct date format string to use will depend on your localization, e.g. in the UK, the correct format string would be dd/mm/yyyy.