Recently, one of my team members needed to get the date for the previous day using PowerShell. I provided the solution for this. In this tutorial, I will explain everything about “PowerShell Get-Date minus 1 day.”
To get the previous day’s date in PowerShell, you can use the Get-Date cmdlet combined with the AddDays method. Simply run (Get-Date).AddDays(-1), which retrieves the current date and subtracts one day from it.
PowerShell Get-Date Minus 1 Day
The Get-Date cmdlet in PowerShell is used to retrieve the current date and time. It’s incredibly useful for scripting and automation tasks where date and time manipulation is required. The syntax is like below:
Get-DateThis command will return the current date and time. However, what if we need the date for the previous day? Let’s explore how to do that.
Subtract Days from the Current Date
To get the date for the previous day, you can subtract one day from the current date. PowerShell makes this easy with the AddDays method. Here’s the syntax:
(Get-Date).AddDays(-1)In this command:
Get-Dateretrieves the current date and time.AddDays(-1)subtracts one day from the current date.
Example
Let’s see this in action:
$yesterday = (Get-Date).AddDays(-1)
Write-Output $yesterdayRunning this script will output the date for the previous day. Here is the exact output you can see in the screenshot below:

Read How to Get Date Without Time in PowerShell?
Alternative Methods to Get the Previous Day’s Date
While the AddDays method is the most straightforward; there are other ways to achieve the same result. Let me show you a few other alternatives.
Using New-TimeSpan
The New-TimeSpan cmdlet can be used to create a time interval, which can then be subtracted from the current date. Here’s how you can do it:
$timeSpan = New-TimeSpan -Days 1
$yesterday = (Get-Date) - $timeSpan
Write-Output $yesterdayIn this example:
New-TimeSpan -Days 1creates a time span of one day.- Subtracting this time span from the current date gives us the previous day’s date.
Here is the exact output in the screenshot below:

Using Date Arithmetic
You can also perform date arithmetic directly using PowerShell’s DateTime object. Here’s an example:
$currentDate = Get-Date
$yesterday = $currentDate.AddDays(-1)
Write-Output $yesterdayThis method is similar to the first example but explicitly stores the current date in a variable before subtracting one day.
You can see the exact output in the screenshot below:

Check out How to Format Date in PowerShell
PowerShell Get-Date Minus 1 Day Examples
Now, let me show you a few real examples of how to get the previous day’s date, which can be incredibly useful in various scenarios. Here are a few practical examples:
Log File Management
If you manage log files and need to archive or process logs from the previous day, this technique can automate the task.
$logDate = (Get-Date).AddDays(-1).ToString("yyyyMMdd")
$logFileName = "log_$logDate.txt"
# Further processing with $logFileNameScheduled Tasks
When setting up scheduled tasks, you might need to reference the previous day’s date for data processing or reporting.
$reportDate = (Get-Date).AddDays(-1).ToString("MM-dd-yyyy")
# Generate report for $reportDateConclusion
In this tutorial, I’ve shown you how to use PowerShell’s Get-Date cmdlet to get the previous day’s date. I have shown different methods like the AddDays method, New-TimeSpan, or direct date arithmetic, etc. I hope you know how to get date minus 1 day in PowerShell.
You may also like:
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.