Hector
Hector

Reputation: 65

Change of format Get-Date` PowerShell

How to do Get-Date to show me this format 2018-01-10 and that does not show the time?

I was currently using Get-Format s but it shows me time.

Upvotes: 0

Views: 1596

Answers (3)

Narasimha Theja Rao
Narasimha Theja Rao

Reputation: 199

Powershell Script to get date as requested

get-date -Format yyyy-MM-dd

Following doc will give you brief explanation on formats

https://technet.microsoft.com/en-us/library/ee692801.aspx

Upvotes: 0

Esperento57
Esperento57

Reputation: 17472

Other method (without get-date):

[System.DateTime]::Today.ToString("yyyy-MM-dd")

Upvotes: 0

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200293

There are several ways to do this. For instance you could use the -Format parameter of the cmdlet:

Get-Date -Format 'yyyy-MM-dd'

You could use the ToString() method of the DateTime object the cmdlet produces:

(Get-Date).ToString('yyyy-MM-dd')

You could also use PowerShell's format operator (-f):

'{0:yyyy-MM-dd}' -f (Get-Date)

Upvotes: 3

Related Questions