CmdID / PowerShell / Cmdlets / Get
Get-Date
Gets the current date and time. PowerShell reference
From the PowerShell reference 11 parameters
What it does
Gets the current date and time. The Get-Date cmdlet gets a DateTime object that represents the current date or a date that you specify. Get-Date can format the date and time in several .NET and Unix formats. You can use Get-Date to generate a date or time character string, and then send the string to other cmdlets or programs. Get-Date uses the current culture settings of the operating system to determine how the output is formatted. To view your computer's settings, use (Get-Culture).DateTimeFormat.
Get-Date [[-Date] <DateTime>] [-Year <Int32>] [-Month <Int32>] [-Day <Int32>] [-Hour <Int32>] [-Minute <Int32>] [-Second <Int32>] [-Millisecond <Int32>] [-DisplayHint <DisplayHintType>] [-Format <String>] [<CommonParameters>]Get-Date [[-Date] <DateTime>] [-Year <Int32>] [-Month <Int32>] [-Day <Int32>] [-Hour <Int32>] [-Minute <Int32>] [-Second <Int32>] [-Millisecond <Int32>] [-DisplayHint <DisplayHintType>] [-UFormat <String>] [<CommonParameters>]
Get the current date and time
Get-DateIdentifyGet elements of the current date and time
Get-Date -DisplayHint DateIdentifyGet the date and time with a .NET format specifier
Get-Date -Format "dddd MM/dd/yyyy HH:mm K"IdentifyGet the date and time with a UFormat specifier
Get-Date -UFormat "%A %m/%d/%Y %R %Z"IdentifyGet a date's day of the year
(Get-Date -Year 2020 -Month 12 -Day 31).DayOfYearIdentifyCheck if a date is adjusted for daylight saving time
$DST = Get-Date
$DST.IsDaylightSavingTime()IdentifyConvert the current time to UTC time
Get-Date -UFormat "%A %B/%d/%Y %T %Z"
$Time = Get-Date
$Time.ToUniversalTime()IdentifyCreate a timestamp
$timestamp = Get-Date -Format o | ForEach-Object { $_ -replace ":", "." }
New-Item -Path C:\Test\$timestamp -Type DirectoryIdentifyShow invariant culture
# Get date using current culture en-US
(Get-Date 2024-03-19).ToString()IdentifyIts page in the reference: Get-Date.
Parameters
-DateSpecifies a date and time. Time is optional and if not specified, returns 00:00:00. Enter the date and time in a format that is standard for the currently selected locale. You can change the current locale using the Set-Culture cmdlet.
For example, in US English:
Get-Date -Date "6/25/2019 12:30:22" returns Tuesday, June 25, 2019 12:30:22-DaySpecifies the day of the month that is displayed. Enter a value from 1 to 31.
If the specified value is greater than the number of days in a month, PowerShell adds the number of days to the month. For example, Get-Date -Month 4 -Day 31 displays May 1, not April 31.-DisplayHintDetermines which elements of the date and time are displayed.
The accepted values are as follows:
- Date: displays only the date
- Time: displays only the time
- DateTime: displays the date and time-FormatDisplays the date and time in the Microsoft .NET Framework format indicated by the format specifier. The Format parameter outputs a String object.
For a list of available .NET format specifiers, see Custom date and time format strings.
When the Format parameter is used, Get-Date only gets the DateTime object's properties necessary to display the date. As a result, some of the properties and methods of DateTime objects might not be available.
Starting in PowerShell 5.0, you can use the following additional formats as values for the Format parameter.
- FileDate. A file or path-friendly representation of the current date in local time. The format is yyyyMMdd (case-sensitive, using a 4-digit year, 2-digit month, and 2-digit day). For example: 20190627.
- FileDateUniversal. A file or path-friendly representation of the current date in universal time (UTC). The format is yyyyMMddZ (case-sensitive, using a 4-digit year, 2-digit month, 2-digit day, and the letter Z as the UTC indicator). For example: 20190627Z.
- FileDateTime. A file or path-friendly representation of the current date and time in local time, in 24-hour format. …-HourSpecifies the hour that is displayed. Enter a value from 0 to 23.-MillisecondSpecifies the milliseconds in the date. Enter a value from 0 to 999.
This parameter was introduced in PowerShell 3.0.-MinuteSpecifies the minute that is displayed. Enter a value from 0 to 59.-MonthSpecifies the month that is displayed. Enter a value from 1 to 12.-SecondSpecifies the second that is displayed. Enter a value from 0 to 59.-UFormatDisplays the date and time in Unix format. The UFormat parameter outputs a string object.
UFormat specifiers are preceded by a percent sign (%), for example, %m, %d, and %Y. The Notes section contains a table of valid UFormat specifiers.-YearSpecifies the year that is displayed. Enter a value from 1 to 9999.