Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
0 like 0 dislike
3.1k views
in PowerShell by 21 28 39

In PowerShell, I am trying to get the current date by running the below script. but As you can see, the date is displayed in long format and I just want to know how to get the current date in PowerShell in short format "yyyy-MM/dd".

PS C:\Users\gracertine> $(Get-Date)

Sunday, November 8, 2020 4:59:15 AM

1 Answer

0 like 0 dislike
by 60 125 265
selected by
 
Best answer

How to get the current date in a short date format in PowerShell?

To get the current date in a short date format in PowerShell, you should use ToString() function as the following:

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

Output

get date in short format in powershell


How to get the current Time in PowerShell?

To get the current Time in Hour:Minutes:Seconds format in PowerShell, you should use the below cmdlet:

$(Get-Date).ToString('hh:mm:ss')

Output

get time in powershell


How to get the AM/PM Time in PowerShell?

To get the current Time in AM/PM format in PowerShell, you should use "tt" as below:

$(Get-Date).ToString('hh:mm:ss tt')

Output

get am pm in powershell

by 21 28 39
0 0
Love you man
If you don’t ask, the answer is always NO!
...