Changing the time stamp on a file or directory under Windows

When you issue the dir command at a command prompt or look at a file or directory through the Windows File Explorer, you will see the last modified date and time listed. If you right-click on the file in the Windows Explorer, you will see three time stamps displayed: created, modified, and accessed. At a command prompt, you can choose which time stamp is displayed using the /T option for the dir command.

  /T          Controls which time field displayed or used for sorting timefield
              C  Creation
              A  Last Access
              W  Last Written

By default, you will see the last written (modified) time stamp. If you wished to see the date and time a file or directory was created, you could use dir /TC. For the last access time, you could use dir /TA.

If you wish to change any of the time stamps, you can do so through Windows PowerShell using a command similar to one of the following commands where name is the file or directory name:

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

E.g., suppose I have a directory with two subdirectories within it. The files were transferred to the system from another system and have time stamps that reflect the time they were copied to the second system, but I want to change those timestamps to match what they were on the original system. If I issue the dir command at a command prompt, I see the following:

Acronis 125x125
C:\Users\JDoe\Documents\Class>dir
 Volume in drive C has no label.
 Volume Serial Number is AADE-A57C

 Directory of C:\Users\JDoe\Documents\Class

09/06/2015  09:27 PM    <DIR>          .
09/06/2015  09:27 PM    <DIR>          ..
09/06/2015  09:27 PM    <DIR>          Unsectioned Items
09/06/2015  09:27 PM    <DIR>          Week 1
               0 File(s)              0 bytes
               4 Dir(s)  697,456,377,856 bytes free

The two directories have a last modified date and time of September 6, 2015 at 9:27 PM. However, on the original system the date they were last modified was July 8, 2013 with a time of 9:10 AM for "Unsectioned Items" and 9:17 AM for "Week 1". To change the created and last written time stamps, I can use the commands below:

C:\Users\JDoe\Documents\Class>powershell
Windows PowerShell
Copyright (C) 2012 Microsoft Corporation. All rights reserved.

PS C:\Users\JDoe\Documents\Class> $(Get-Item "Week 1").creationtime=$(Get-Date "07/08/2013 09:17 AM")
PS C:\Users\JDoe\Documents\Class> $(Get-Item "Week 1").lastwritetime=$(Get-Date "07/08/2013 09:17 AM")
PS C:\Users\JDoe\Documents\Class> exit
C:\Users\JDoe\Documents\Class>

If I then check the last written, created, and accessed time stamps, I see that the written and created time stamps have changed, but the last accessed time stamp remains unchanged for that directory. Issuing the dir command with no options is the same as issuing the command dir /TW.

C:\Users\JDoe\Documents\Class>dir
 Volume in drive C has no label.
 Volume Serial Number is AADE-A57C

 Directory of C:\Users\JDoe\Documents\Class

09/06/2015  09:27 PM    <DIR>          .
09/06/2015  09:27 PM    <DIR>          ..
09/06/2015  09:27 PM    <DIR>          Unsectioned Items
07/08/2013  09:17 AM    <DIR>          Week 1
               0 File(s)              0 bytes
               4 Dir(s)  697,485,160,448 bytes free

C:\Users\JDoe\Documents\Class>dir /TC
 Volume in drive C has no label.
 Volume Serial Number is AADE-A57C

 Directory of C:\Users\JDoe\Documents\Class

09/06/2015  09:27 PM    <DIR>          .
09/06/2015  09:27 PM    <DIR>          ..
09/06/2015  09:27 PM    <DIR>          Unsectioned Items
07/08/2013  09:17 AM    <DIR>          Week 1
               0 File(s)              0 bytes
               4 Dir(s)  697,485,160,448 bytes free

C:\Users\JDoe\Documents\Class>dir /TA
 Volume in drive C has no label.
 Volume Serial Number is AADE-A57C

 Directory of C:\Users\JDoe\Documents\Class

09/06/2015  09:27 PM    <DIR>          .
09/06/2015  09:27 PM    <DIR>          ..
09/06/2015  09:27 PM    <DIR>          Unsectioned Items
09/06/2015  09:27 PM    <DIR>          Week 1
               0 File(s)              0 bytes
               4 Dir(s)  697,485,160,448 bytes free

If you receive the message, "The process cannot access the file ... because it is being used by another process", make sure that if you are using the Windows File Explorer that you are in a directory above the one whose time stamp you wish to change.

You can use wildcard characters, e.g., an asterisk, to change the time stamps on multiple files at once. You can also use a 24-hour clock format, i.e, "military time" for the time format. E.g.:

PS>dir


    Directory: C:\Users\JDoe\Documents\ISO


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---          9/7/2015   2:29 PM  209762304 slax-6.1.2.iso


PS C:\Users\JDoe\Documents\ISO> $(Get-Item *.iso).creationtime=$(Get-Date "05/07/2010 15:00")
PS C:\Users\JDoe\Documents\ISO> $(Get-Item *.iso).lastwritetime=$(Get-Date "05/07/2010 15:00")
PS C:\Users\JDoe\Documents\ISO> dir


    Directory: C:\Users\JDoe\Documents\ISO


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---          5/7/2010   3:00 PM  209762304 slax-6.1.2.iso


PS C:\Users\JDoe\Documents\ISO>

References:

  1. How can I change the timestamp on a file? [duplicate]
    Date: June 3, 2011
    Super User

 

TechRabbit ad 300x250 newegg.com

Justdeals Daily Electronics Deals1x1 px

Valid HTML 4.01 Transitional

Created: Monday September 7, 2015