Saturday, 17 August 2013

loop to minus 15 days from the current date

loop to minus 15 days from the current date

I'm trying to figure out what would be the best way to call an exe that
requires a date range parameter (ex: 20130801-20130815) and then loop it
so it minuses 15 days and calls the exe with the new date range.
I thought of using a do until but i'm not sure how (new to
powershell/programming) but I'm sure this is far from the right method :).
I've just started to figure this out, so thanks in advance for any/all
help.
do {
$startDate = (Get-Date).adddays(-34)
$requireddate = some date that is set ad-hoc
$startdate.ToString("yyyyMMdd")
#[datetime]::parseexact($startdate,"MMddyyyy",$null)
Call THE EXE at this point with the parameters $startdate and $enddate
$enddate = $startdate.AddDays(-15)
write-host $enddate.ToString("yyyyMMdd")
}
until ($enddate -eq $requireddate)

No comments:

Post a Comment