tags:

views:

29

answers:

2

I am trying to use the Get-Date cmdlet to get yesterdays date. I have found the .AddDay(-1) command and that seems to work. The next thing i need to do is extract the date in YYMMDD format. This is that part i can not figure out how to do.

This is what i used to get todays date and the previous day.

 $a = Get-Date
"Day: " + $a.Day
"Month: " + $a.Month
"Year: " + $a.Year
"Hour: " + $a.Hour
"Minute: " + $a.Minute
"Second: " + $a.Second

$b=$a.AddDays(-1)
"Day: " + $b.Day
"Month: " + $b.Month
"Year: " + $b.Year
"Hour: " + $b.Hour
"Minute: " + $b.Minute
"Second: " + $b.Second
+1  A: 
$a = Get-Date
$b=$a.AddDays(-1)
$b.ToString("yyMMdd")

(or)

$c = $b.ToString("yyMMdd")
Mark
+4  A: 

Try this:

$b = (Get-Date).AddDays(-1).ToString("yyMMdd")
kbrimington