How to format a date in PowerShell?
There are a lot of methods to do this and two easy way, the
easy or the hard way.
Easy way are the methods below:
#Method 1
$year = (get-date -UFormat "%D")
Write-Output ("Method 1: " + $year +
"`n`r")
#Method 2
$year = (get-date -UFormat "%m-%d-%y")
Write-Output ("Method 2: " + $year +
"`n`r")
#Method 3
$year = (get-date -UFormat "%d-%m-%y")
Write-Output ("Method 3: " + $year +
"`n`r")
#Method 4
$year = (get-date -UFormat "%d/%m/%y")
Write-Output ("Method 4: " + $year +
"`n`r")
Sample output:
Method 1: 04/23/20
Method 2: 04-23-20
Method 3: 23-04-20
Method 4: 23/04/20
Image output below:
For a complete year output, use capital Y.
$year = (get-date -UFormat "%d-%m-%Y")
Write-Output ("Method 5: " + $year +
"`n`r")
Output:
Method 5: 23-04-2020
Cheers. Till next time. Hope it helps. :)
================================
Free Android Apps:
Click links below to find out more:
Excel Keyboard guide:
Heaven's Dew Fall Prayer app for Android :
Catholic Rosary Guide for Android:
Comments
Post a Comment