I have a powershell GUI calendar in which you can select a range of dates. I need to be able to covert that info into an array of dates formatted YYYYMMDD.
I know $Date = “{0:yyyyMMdd}” -f (Get-Date) will work but I can’t seem to get the items into the array.
I need an array like this:
20130211
20130212
20130213
Here’s the code so far. Thanks for your help!
$Calendar = New-Object System.Windows.Forms.MonthCalendar
$Calendar.Location = New-Object System.Drawing.Size(10,80)
$Calendar.ShowTodayCircle = $False
$Calendar.MaxDate = (Get-Date).AddDays(1)
$Calendar.MaxSelectionCount = $CalendarSelect
$MenuBox.Controls.Add($Calendar)
$Dates = $Calendar.SelectionRange
So $Dates will need to be converted into the array. Thanks again!
The
SelectionRangeproperty ofMonthCalendarreturns a SelectionRange object with aStartandEndproperty indicating the start and end of the range. You will need to just loop through the range to get the output you want: