How To Format DateTime In PowerShell?

PowerShell provides the Get-Date command in order to print or display date and time information. The GetDate command print or display the current date and time in .Net or Unix format. But the Get-Date command supports a lot of different date and time formats which will be explained in this tutorial.

Default DateTime Format

When the Get-Date format is used without any parameter or option the following format is used. The “Day, Month, Day of Month, Year Hour:Minute:Second” format is used.

PS> Get-Date
Tuesday, August 16, 2022 7:26:43 AM

Format Specifiers

Get-Date command provides the -Format option in order to set different formats. The following format specifiers can be used to express different formats.

SpecifierDefinition
ddddDay of the week – full name
MMMonth number
ddDay of the month – 2 digits
yyyyYear in 4-digit format
HH:mmTime in 24-hour format – no seconds
KTime zone offset from Universal Time Coordinate (UTC)

In the following example, we print the date in “ddMMyyyy” format.

PS> Get-Date -Format "ddMMyyyy"
16082022

UFormat Specifiers

The Get-Date command also provides the Unix format specifiers via the -UFormat .

SpecifierDefinition
%ADay of the week – full name
%mMonth number
%dDay of the month – 2 digits
%YYear in 4-digit format
%RTime in 24-hour format – no seconds
%ZTime zone offset from Universal Time Coordinate (UTC)

List Format Types

The Get-Date command can be used to list all supported date and time formats. The GetDateTimeFormats() is used in lots of different formats supported by date and time objects.

(Get-Date).GetDateTimeFormats()
8/16/2022
8/16/22
08/16/22
08/16/2022
22/08/16
2022-08-16
16-Aug-22
Tuesday, August 16, 2022
August 16, 2022
Tuesday, 16 August, 2022
16 August, 2022
Tuesday, August 16, 2022 8:12 AM
Tuesday, August 16, 2022 08:12 AM
Tuesday, August 16, 2022 8:12
Tuesday, August 16, 2022 08:12
August 16, 2022 8:12 AM
August 16, 2022 08:12 AM
August 16, 2022 8:12
August 16, 2022 08:12
Tuesday, 16 August, 2022 8:12 AM
Tuesday, 16 August, 2022 08:12 AM
Tuesday, 16 August, 2022 8:12
Tuesday, 16 August, 2022 08:12
16 August, 2022 8:12 AM
16 August, 2022 08:12 AM
16 August, 2022 8:12
16 August, 2022 08:12
Tuesday, August 16, 2022 8:12:04 AM
Tuesday, August 16, 2022 08:12:04 AM
Tuesday, August 16, 2022 8:12:04
Tuesday, August 16, 2022 08:12:04
August 16, 2022 8:12:04 AM
August 16, 2022 08:12:04 AM
August 16, 2022 8:12:04
August 16, 2022 08:12:04
Tuesday, 16 August, 2022 8:12:04 AM
Tuesday, 16 August, 2022 08:12:04 AM
Tuesday, 16 August, 2022 8:12:04
Tuesday, 16 August, 2022 08:12:04
16 August, 2022 8:12:04 AM
16 August, 2022 08:12:04 AM
16 August, 2022 8:12:04
16 August, 2022 08:12:04
8/16/2022 8:12 AM
8/16/2022 08:12 AM
8/16/2022 8:12
8/16/2022 08:12
8/16/22 8:12 AM
8/16/22 08:12 AM
8/16/22 8:12
8/16/22 08:12
08/16/22 8:12 AM
08/16/22 08:12 AM
08/16/22 8:12
08/16/22 08:12
08/16/2022 8:12 AM
08/16/2022 08:12 AM
08/16/2022 8:12
08/16/2022 08:12
22/08/16 8:12 AM
22/08/16 08:12 AM
22/08/16 8:12
22/08/16 08:12
2022-08-16 8:12 AM
2022-08-16 08:12 AM
2022-08-16 8:12
2022-08-16 08:12
16-Aug-22 8:12 AM
16-Aug-22 08:12 AM
16-Aug-22 8:12
16-Aug-22 08:12
8/16/2022 8:12:04 AM
8/16/2022 08:12:04 AM
8/16/2022 8:12:04
8/16/2022 08:12:04
8/16/22 8:12:04 AM
8/16/22 08:12:04 AM
8/16/22 8:12:04
8/16/22 08:12:04
08/16/22 8:12:04 AM
08/16/22 08:12:04 AM
08/16/22 8:12:04
08/16/22 08:12:04
08/16/2022 8:12:04 AM
08/16/2022 08:12:04 AM
08/16/2022 8:12:04
08/16/2022 08:12:04
22/08/16 8:12:04 AM
22/08/16 08:12:04 AM
22/08/16 8:12:04
22/08/16 08:12:04
2022-08-16 8:12:04 AM
2022-08-16 08:12:04 AM
2022-08-16 8:12:04
2022-08-16 08:12:04
16-Aug-22 8:12:04 AM
16-Aug-22 08:12:04 AM
16-Aug-22 8:12:04
16-Aug-22 08:12:04
August 16
August 16
2022-08-16T08:12:04.7614979+03:00
2022-08-16T08:12:04.7614979+03:00
Tue, 16 Aug 2022 08:12:04 GMT
Tue, 16 Aug 2022 08:12:04 GMT
2022-08-16T08:12:04
8:12 AM
08:12 AM
8:12
08:12
8:12:04 AM
08:12:04 AM
8:12:04
08:12:04
2022-08-16 08:12:04Z
Tuesday, August 16, 2022 5:12:04 AM
Tuesday, August 16, 2022 05:12:04 AM
Tuesday, August 16, 2022 5:12:04
Tuesday, August 16, 2022 05:12:04
August 16, 2022 5:12:04 AM
August 16, 2022 05:12:04 AM
August 16, 2022 5:12:04
August 16, 2022 05:12:04
Tuesday, 16 August, 2022 5:12:04 AM
Tuesday, 16 August, 2022 05:12:04 AM
Tuesday, 16 August, 2022 5:12:04
Tuesday, 16 August, 2022 05:12:04
16 August, 2022 5:12:04 AM
16 August, 2022 05:12:04 AM
16 August, 2022 5:12:04
16 August, 2022 05:12:04
August 2022
August 2022
See also  What Does "cmd /c" Means In Windows MS-DOS?

Leave a Comment