Reputation: 65
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
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
Reputation: 17472
Other method (without get-date):
[System.DateTime]::Today.ToString("yyyy-MM-dd")
Upvotes: 0
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