Recently, I got a scenario where I needed to calculate future dates based on a specific number of days. The Get-Date cmdlet in PowerShell provides the adddays() method to achieve this. In this tutorial, I will explain how to add days to a date using the PowerShell Get-Date cmdlet.
PowerShell Add Days to Date
The Get-Date cmdlet in PowerShell is used to work with dates and times. It allows you to retrieve the current date and time, as well as perform various date and time calculations. By default, when you run the Get-Date cmdlet without any parameters, it returns the current system date and time.
To add days to a specific date using the Get-Date cmdlet, you can use the -Date parameter followed by the desired date and the -Format parameter to specify the output format. Here’s an example:
Get-Date -Date "2025-06-01" -Format "yyyy-MM-dd"
This command will output: 2025-06-01
Now, let’s say you want to add 30 days to this date. You can achieve this by using the AddDays method:
(Get-Date -Date "2025-06-01").AddDays(30)
The output will be: 01 July 2025 00:00:00
Here is the exact output in the screenshot below:
As you can see, the AddDays method allows you to specify the number of days you want to add to the given date. The result is the future date based on the specified number of days.
Check out PowerShell Get-Date Minus 1 Day
PowerShell Get-Date Adddays Format
By default, the Get-Date cmdlet returns the date and time in a default format. However, you can customize the output format using the -Format parameter. PowerShell provides various format specifiers that you can use to display the date and time in different formats. Here are a few commonly used format specifiers:
- “yyyy-MM-dd”: Displays the date in the format “year-month-day”
- “MM/dd/yyyy”: Displays the date in the format “month/day/year”
- “dddd, MMMM d, yyyy”: Displays the date in a long format, including the day of the week, month name, day, and year
Here’s an example that demonstrates formatting the output:
(Get-Date -Date "2025-06-01").AddDays(30) | Get-Date -Format "dddd, MMMM d, yyyy"
The output will be: Tuesday, July 1, 2025.
You can also see the output in the screenshot below:
Read PowerShell check if file modified in last 24 hours
Add Days to Today’s Date using Get-Date in PowerShell
In many scenarios, you may need to calculate a future date based on the current date. PowerShell makes it easy to add days to today’s date using the Get-Date cmdlet. Here’s an example:
$today = Get-Date
$futureDate = $today.AddDays(15)
Write-Host "Today's Date: $($today.ToString('yyyy-MM-dd'))"
Write-Host "Future Date: $($futureDate.ToString('yyyy-MM-dd'))"
In this example, we first retrieve today’s date using the Get-Date cmdlet and store it in the $today variable. Then, we use the AddDays method to add 15 days to today’s date and store the result in the $futureDate variable.
Finally, we use Write-Host to display both today’s date and the calculated future date. We format the dates using the ToString method with the ‘yyyy-MM-dd’ format specifier to display them in the “year-month-day” format.
Let’s say today’s date is Nov 26, 2024. The output of the above code will be:
Today's Date: 2024-11-26
Future Date: 2024-12-11
This example shows how easily you can add a specific number of days to today’s date using PowerShell.
Here is the exact output in the screenshot below:
You can modify the number of days added to today’s date by changing the value passed to the AddDays method. For example, to add 30 days to today’s date, you would use $futureDate = $today.AddDays(30).
Read PowerShell Get-date Format Milliseconds
Add Business Days to Date using PowerShell
In many business scenarios, you may need to calculate future dates based on business days, excluding weekends. PowerShell doesn’t have a built-in function for this, but you can create a custom function to achieve it. Here’s an example function that adds business days to a given date:
function Add-BusinessDays {
param(
[DateTime]$Date,
[int]$Days
)
$count = 0
while ($count -lt $Days) {
$Date = $Date.AddDays(1)
if ($Date.DayOfWeek -ne "Saturday" -and $Date.DayOfWeek -ne "Sunday") {
$count++
}
}
return $Date
}
To use this function, you can call it with the desired date and the number of business days you want to add:
$startDate = Get-Date -Date "2023-06-01"
$futureDate = Add-BusinessDays -Date $startDate -Days 22
In this example, we start with the date June 1, 2023, and add 22 business days. The resulting future date will be calculated accordingly, excluding weekends.
Conclusion
In this tutorial, we explored how to add days to a date using the PowerShell Get-Date cmdlet. We covered the basics of the Get-Date cmdlet, how to add days to a specific date, and how to format the output. Additionally, we discussed calculating dates based on business days using get-date adddays method in PowerShell.
You may also like:
I am Bijay a Microsoft MVP (10 times – My MVP Profile) in SharePoint and have more than 17 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com