Monthly Archive

Categories

Get-Date –Format

Get-Date –Format enables you to control the formatting of the datetime object returned by the cmdlet.

A standard call to get date returns:

PS> Get-Date

27 May 2019 12:36:47

 

The –Format parameter takes a value from the DateTimeFormatInfo class - https://docs.microsoft.com/en-us/dotnet/api/system.globalization.datetimeformatinfo?view=netframework-4.8 – to specify how you want the information to be formatted.

 

For instance:

Short and long forms of the date with no time

PS> Get-Date -Format d
27/05/2019
PS> Get-Date -Format D
27 May 2019

 

Full date and short or long time

PS> Get-Date -Format f
27 May 2019 12:48
PS> Get-Date -Format F
27 May 2019 12:48:38

 

No year or time

PS> Get-Date -Format m
27 May
PS> Get-Date -Format M
27 May

 

RFC1123 compliant

PS> Get-Date -Format R
Mon, 27 May 2019 12:50:07 GMT
PS> Get-Date -Format r
Mon, 27 May 2019 12:50:10 GMT

 

Sortable

PS> Get-Date -Format s
2019-05-27T12:50:45

 

Short and long time only

PS> Get-Date -Format t
12:51
PS> Get-Date -Format T
12:51:14

 

Sortable Universal time

PS> Get-Date -Format u
2019-05-27 12:51:55Z

Z refers to the time zone

 

Specify day month year format

PS> Get-Date -Format 'dd/MM/yyyy'
27/05/2019

Comments are closed.