Scripting Games 2008 Beginners Windows PowerShell Event 5
My solution for Beginners Event 5: What’s the Difference (that I forgot to send in ) :
PARAM([datetime]$date = 'March 3, 2009')
$now = [datetime]::Today
$d = ($date - $now).days
"Days: $d"
$m = ($date.year - $now.year) * 12 + $date.month - $now.month
'Months: ' + $m
if ($m -gt 0 ) {
if ($now.day -gt $date.day ) {
$d = ( Get-Culture ).Calendar.GetDaysInMonth($now.year,$now.month) - $now.day + $date.day
$m--
} else {
$d = $date.day - $now.day
}
}
"Months/Days: $m / $d "
This event was more interesting as it did look at first glance as you needed to calculate month and days also.
Enjoy,
Greetings /\/\o\/\/