How to Change File (s) Date & Timestamp via CMD or PowerShell?
Changing a file’s date and timestamp can be useful for organizing documents, correcting metadata errors, or maintaining consistency in professional workflows. On Windows systems, every file carries multiple timestamps, such as Created Date, Modified Date, and Accessed Date. While these values are typically managed automatically by the operating system, you can manually adjust them using built-in tools like Command Prompt (CMD) and PowerShell.
If you are someone who prefers command-line tools over third-party software, learning how to modify timestamps through CMD or PowerShell gives you greater control and flexibility.
In this guide, I will walk you through everything, ensuring you understand both the process and the reasoning behind it.
How to Change File(s) Date & Timestamp via CMD or PowerShell?

To change file timestamps in Windows, you can use third-party tools like NirCmd with Command Prompt or built-in PowerShell commands such as Set-ItemProperty. PowerShell allows direct editing of CreationTime, LastWriteTime, and LastAccessTime, while CMD requires external utilities for full control.
Every file in Windows contains three key timestamp values. The Creation Date shows when the file was first created. The Last Modified Date indicates when the file was last saved or updated. The Last Accessed Date records the last time someone opened or viewed the file.
These attributes are stored as part of the file’s metadata and can be modified when needed. While PowerShell provides built-in commands to change these values, CMD requires external tools like NirCmd to achieve the same level of control.
Understanding these basics will help you choose the right method and avoid confusion during the process.
Step 1: Understand File Date and Timestamp Attributes
Before making any changes, you need a clear understanding of the three main timestamp attributes.
The first is the Creation Time, which tells you when the file originally came into existence. The second is the Last Modified Time, which updates whenever the file is edited or saved. The third is the Last Access Time, which changes when the file is opened or viewed.
These values are automatically updated by Windows, but they can also be manually adjusted. Knowing the difference between them ensures you modify the correct attribute based on your needs.
For instance, if you want a file to appear older, you would change its Creation Time. If you want it to look recently edited, you would update the Last Modified Time instead.
Step 2: Change File Timestamp Using CMD with NirCmd
The Command Prompt does not natively support changing file timestamps directly. However, you can extend its functionality using a lightweight tool called NirCmd.
To get started, download NirCmd from its official source and extract the files. After extraction, add the NirCmd folder to your system’s PATH so that CMD can recognize its commands from any location.
Next, open Command Prompt as an administrator. This ensures you have the required permissions to modify file attributes.
Navigate to the folder containing your file using the directory change command. Once you are inside the correct folder, you can use the NirCmd command to modify timestamps.
For example, you can run the following command:
nircmd setfiletime “example.txt” “15-03-2023 10:22:30” “15-03-2023 10:22:30” “15-03-2023 10:22:30”
This command updates the Creation Time, Last Modified Time, and Last Access Time of the file named example.txt to March 15, 2023, at 10:22:30 AM.
Make sure you follow the correct date format, which is dd-mm-yyyy hh:mm:ss, otherwise the command may fail.
If you want to quickly set the file’s timestamp to the current date and time, you can use the “now” keyword like this:
nircmd setfiletime “example.txt” now now now
This is a convenient shortcut when you do not need a specific timestamp.
Step 3: Batch Change File Timestamp Using CMD Loop
If you need to modify multiple files at once, CMD offers a powerful looping mechanism called the for /r loop. While CMD alone cannot change timestamps, combining it with NirCmd allows batch processing.
The basic syntax of the loop looks like this:
for /r [Path] %i in ([SearchMask]) do [Command] %i
In this structure, the path defines where the search begins, the search mask filters specific file types, and the command applies changes to each file.
To update timestamps for multiple files, navigate to the target folder and run a command like this:
for /r %i in (*) do nircmd setfiletime “%i” “15-03-2023 10:23:38” “15-03-2023 10:23:38”
This command will update the creation and modification timestamps for all files in the folder and its subfolders.
Batch processing is especially useful when working with large collections of files, such as documents, images, or logs.
Step 4: Use PowerShell to Change File Timestamp
PowerShell is a more advanced and powerful alternative to CMD. It includes built-in commands that allow you to modify file timestamps without relying on external tools.
The key command used here is Set-ItemProperty, which allows you to change file properties, including timestamps.
The basic syntax is:
Set-ItemProperty -Path [Path] -Name [PropertyName] -Value [NewValue]
You need to specify the file path, the property you want to change, and the new value.
Start by opening PowerShell as an administrator. Then create a new date object using the Get-Date command:
$NewDate = Get-Date -Year 2023 -Month 3 -Day 15 -Hour 10 -Minute 22 -Second 30
This defines the exact date and time you want to apply.
Next, update the file’s timestamps using the following commands:
Set-ItemProperty -Path “example.txt” -Name CreationTime -Value $NewDate
Set-ItemProperty -Path “example.txt” -Name LastWriteTime -Value $NewDate
These commands will set both the creation and modification dates of the file.
5: Change Last Access Time Using PowerShell
In addition to creation and modification dates, you can also update the last accessed time using PowerShell.
To do this, use the same Set-ItemProperty command but specify the LastAccessTime property:
Set-ItemProperty -Path “example.txt” -Name LastAccessTime -Value $NewDate
This updates the timestamp that records when the file was last opened.
This step is useful when you want full control over all aspects of file metadata.
Step 6: Batch Change File Timestamps Using PowerShell
PowerShell makes it easy to update multiple files at once using the ForEach-Object cmdlet.
First, gather the files using the Get-ChildItem command. Then apply changes to each file using ForEach-Object.
Here is an example:
Get-ChildItem -Path “C:\example*.txt” | ForEach-Object {
Set-ItemProperty -Path $.FullName -Name CreationTime -Value $NewDate
Set-ItemProperty -Path $.FullName -Name LastWriteTime -Value $NewDate
}
This command updates all text files in the specified folder.
If your files are located in subfolders, you can include the -Recurse parameter:
Get-ChildItem -Path “C:\example*.txt” -Recurse | ForEach-Object {
Set-ItemProperty -Path $.FullName -Name CreationTime -Value $NewDate
Set-ItemProperty -Path $.FullName -Name LastWriteTime -Value $NewDate
}
This ensures that all matching files, including those in nested directories, are updated.
When entering multi-line commands in PowerShell, press Shift and Enter to move to the next line, and press Enter only after completing the entire command.
FAQs
What are file timestamp attributes in Windows?
They are metadata values that store when a file was created, modified, and last accessed.
Can CMD change file timestamps without tools?
No, CMD requires external tools like NirCmd to modify timestamps directly.
Is PowerShell better than CMD for this task?
Yes, PowerShell provides built-in commands and more flexibility for editing file metadata.
What format should I use for dates in NirCmd?
You should use the format dd-mm-yyyy hh:mm:ss for accurate results.
Can I modify multiple files at once?
Yes, both CMD with loops and PowerShell with ForEach-Object allow batch processing.
Do I need administrator permissions?
In most cases, yes, especially when modifying system or protected files.
