Quick and Easy Day of the Week Date Picker
$today = [datetime]::Today $dates = @() for($i = $today.AddDays(0).DayOfWeek.value__; $i -ge 0; $i--){ $dates += $today.AddDays(-$i) } $date = $dates | Out-GridView -PassThru
Find Date in MM/DD/YYYY Pattern in String
[Regex]::Matches($string, '(((0?[1-9]|1[012])/(0?[1-9]|1\d|2[0-8])|(0?[13456789]|1[012])/(29|30)|(0?[13578]|1[02])/31)/(19|[2-9]\d)\d{2}|0?2/29/((19|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(([2468][048]|[3579][26])00)))').Value
Convert From WMI Datetime
[Management.ManagementDateTimeConverter]::ToDateTime($WMIDate)
First Weekday of Month
# Get first day of Month $FirstWeekDay = Get-Date $date.Date -day 1 # if day is Sat or Sun add days until it is not while(0,6 -contains $FirstWeekDay.DayOfWeek.value__){ $FirstWeekDay = $FirstWeekDay.AddDays(1) } $FirstWeekDay
Last Weekday of Month
# Get last day of Month $LastWeekDay = (Get-Date $date.Date -day 1).AddMonths(1).AddMilliseconds(-1) # if day is Sat or Sun subtract days until it is not while(0,6 -contains $LastWeekDay.DayOfWeek.value__){ $LastWeekDay = $LastWeekDay.AddDays(-1) } $LastWeekDay
Convert Between Time Zones
$DateTime = [DateTime]::SpecifyKind($date, [DateTimeKind]::Unspecified) $from = [System.TimeZoneInfo]::FindSystemTimeZoneById($FromTimeZone) $to = [System.TimeZoneInfo]::FindSystemTimeZoneById($ToTimeZone) $utc = [System.TimeZoneInfo]::ConvertTimeToUtc($DateTime, $from) [System.TimeZoneInfo]::ConvertTime($utc, $to)
Search for a Time Zones
[System.TimeZoneInfo]::GetSystemTimeZones() | Where-Object{$_.DisplayName -like "*$($Name)*" -or $_.DaylightName -like "*$($Name)*" -or $_.StandardName -like "*$($Name)*" -or $_.Id -like "*$($Name)*"}