Add to Technorati Favorites
Welcome to ThePowerShellGuy.com Sign in | Join | Help

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\/\/

Published Tuesday, February 26, 2008 3:59 PM by MoW

Comments

# 2008 Scripting Games - Solution for Beginner’s Event 5

Friday, February 29, 2008 12:44 AM by 2008 Scripting Games - Solution for Beginner’s Event 5
Anonymous comments are disabled