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 – – 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
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


PS> Get-Date -Format s

Short and long time only

PS> Get-Date -Format t
PS> Get-Date -Format T

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’

This entry was posted in Powershell Basics. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s