How can I change the timestamp on a file?

Due to William Jackson's answer, I found a similar question on Stack Overflow.

The accepted answer states to use Powershell and these commands:

$(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")

Edit

Two examples:

(This one is from the comments:) Set the last-access time for a file aaa.csv to the current time:

$(Get-Item aaa.csv).lastwritetime=$(Get-Date)

Set the creation time of a file foo.txt to November 24, 2015, at 6:00am:

$(Get-Item foo.txt).creationtime=$(Get-Date "11/24/2015 06:00 am")

See the answers to this question.

Specifically, this can be done natively with:

copy /b filename.ext +,,

This will set the timestamp to the current time.

Documentation for the copy command is on TechNet.

The commas indicate the omission of the Destination parameter.


Nirsoft to the rescue: try the freeware tool nircmd. It's a bunch of useful tools in one small command line program. One of the commands allows you to specify either or both of created time and modified time, like this:

nircmd.exe setfiletime "c:\temp\myfile.txt" "24-06-2003 17:57:11" "22-11-2005 10:21:56"