How To Change Date Via PowerShell

Windows PowerShell offers the flexibility to modify the current date of your operating system. You can set a specific date or adjust the time by moving it forward or backward.

This capability can be useful in various scenarios. For instance, if you’re testing time-sensitive applications or simulations, being able to manipulate the system date can help ensure accurate results. It can also be handy for troubleshooting date and time-setting issues.

Advertisements

With Windows PowerShell, changing the current date is straightforward. You can specify the desired date and time, allowing you to customize it according to your requirements.

Change the Windows date using a script.

There are situations when the current date in Windows needs to be adjusted temporarily. Of course, this could be done manually by right-clicking on the time in the taskbar, but if you do that in a script, Change the Windows date, or want to do something else.

Advertisements

How To Change Date Via PowerShell

Since in the Windows environment, I work almost exclusively with the PowerShell* work; I would like to describe a solution for this, with which the date can be changed to any value very quickly. The whole thing works with the cmdlet set date and is anything but difficult to implement.

Advertisements
Set-Date -date "14.11.2017 18:00"

The above command’s disadvantage is its advantage: an arbitrary fixed value is specified. In scripts, however, you sometimes have to change the date variably. For example: subtract 2 hours from the current time, or add 5 hours. But PowerShell also offers a solution for this.

  How to Terminate Processes in Time-Controlled Manner Via PowerShell

Add or subtract days, hours, and minutes.

I set the operating system date in the example below seven days ago. This works with the short command:

Advertisements
Set-Date (Get-Date).AddDays(-7)

First, with (get date) read in the current date or the current time. Then using AddDays(x) add a certain number of days. If the value x is negative, this is subtracted. Alternative to AddDays can also change the parameters AddMinutes or AddSeconds to be appended.

Example:

Set-Date (Get-Date).AddDays(-7).AddMinutes(10).AddSeconds(20)

If the time is only to be set back or forward by a particular value, this can be done with the simple parameter -adjust feasibly:

Set-Date -adjust -1:30:0

This resets the current operating system time by 1.5 hours.

Conclusion

As you can see, the Windows date can be changed quickly and easily using PowerShell. Using the parameters -adjust or AddDays (etc.), a certain number of days, hours, or minutes can also be added to or subtracted from the current time.

Author
Follow:
Rohit is a certified Microsoft Windows expert with a passion for simplifying technology. With years of hands-on experience and a knack for problem-solving, He is dedicated to helping individuals and businesses make the most of their Windows systems. Whether it's troubleshooting, optimization, or sharing expert insights,