While planning for a PowerShell webinar, I prepared for PowerShell Get-Date. In this tutorial, I will explain the PowerShell Get-Date cmdlet with examples.
The Get-Date cmdlet in PowerShell is used to retrieve the current date and time of the system. Simply running Get-Date without any parameters will return the current date and time in the default format. This cmdlet is incredibly useful for tasks that require date and time information, such as logging events or scheduling tasks.
What is PowerShell Get-Date?
The Get-Date cmdlet in PowerShell is used to retrieve the current date and time of the system. It can also be used to format dates, perform date arithmetic, and convert date formats. This cmdlet is useful for scripting and automation tasks that require date and time information.
Syntax
The basic syntax of the Get-Date cmdlet is:
Get-DateHowever, Get-Date comes with several parameters that allow for more advanced usage:
Get-Date [-Date] <DateTime> [-DisplayHint {Date | Time | DateTime}] [-Format <String>] [-UFormat <String>] [<CommonParameters>]Basic Usage
Let’s start with the simplest form of Get-Date:
Get-DateThis command will return the current date and time of your system.
I executed the above PowerShell cmdlet, and you can see the output in the screenshot below:

Format Dates
One of the powerful features of Get-Date is its ability to format dates. You can use the -Format parameter to specify the date format you need. Here are some examples:
Get-Date -Format "MM/dd/yyyy"You can see the output in the screenshot below:

This will return the date in the format MM/dd/yyyy, such as 09/15/2024.
Get-Date -Format "dddd, MMMM dd, yyyy"This command will return the date in a more readable format like Sunday, September 15, 2024.
Check out Get Date Without Time in PowerShell
Date Arithmetic
You can perform date arithmetic using Get-Date. For instance, to get the date 5 days from now, you can use the AddDays method:
(Get-Date).AddDays(5)Similarly, to get the date 3 months ago:
(Get-Date).AddMonths(-3)Get Specific Parts of the Date
Sometimes, you might only need specific parts of the date, such as the year, month, or day. You can easily extract these using the properties of the DateTime object returned by Get-Date:
(Get-Date).Year
(Get-Date).Month
(Get-Date).DayPowerShell Get-Date Examples
Now, let me show you a few examples of PowerShell Get-Date.
Calculate Age
Let’s say you want to calculate someone’s age based on their birthdate. Here’s how you can do it:
$birthdate = Get-Date "1990-01-01"
$today = Get-Date
$age = $today.Year - $birthdate.Year
if ($birthdate > $today.AddYears(-$age)) { $age-- }
$ageSchedule a Task
If you need to schedule a task to run at a specific time, you can calculate the time difference and use Start-Sleep:
$futureTime = (Get-Date).AddHours(2)
$timeDifference = $futureTime - (Get-Date)
Start-Sleep -Seconds $timeDifference.TotalSeconds
# Task to run after 2 hours
Write-Output "Task is running now!"Convert Time Zones
You can also convert between time zones using Get-Date:
$utcTime = Get-Date -Format "yyyy-MM-ddTHH:mm:ssZ"
$localTime = [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId([System.DateTime]::Parse($utcTime), "Pacific Standard Time")
$localTimeConclusion
In this tutorial, I have explained everything about the Get-Date PowerShell cmdlet and shown a few real examples of the PowerShell Get-Date.
You may also like the following tutorials:
- How to Add Days to a Date in PowerShell?
- PowerShell Get-Date Minus 1 Day
- How to Get Date and Time in 24-Hour Format in PowerShell?
- Get Date Differences Between Two Dates in PowerShell
- How to Check If Date Is Older Than 30 Days in PowerShell?
- Compare Dates Without Time in PowerShell
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.