Powershell: how to format get-date for string and remove 0?

I am trying to remove leading zeros in my date when I run the get-date cmdlet by trying:

$filedate = get-date -uformat "%m-%d-%Y" 
$filedate = $filedate.ToString().Replace("0", "")

      

this returns "01-04-2008"

I want the output to be "1-4-2008"

any ideas for another way to do this?

early

+11


source to share


3 answers


$filedate = get-date -format "M-d-yyyy"

      



+17


source


$ fileDate = $ fileDate.ToString ("Md-yyyy")



+1


source


use a format string like:

get-date -format yyyy/M/d

      

or

Get-Date.toString (yyyy / M / y)

0


source







All Articles