header image

Get-Date –Format

Posted by: | May 27, 2019 Comments Off on 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
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’

under: PowerShell Basics

Comments are closed.