Thursday 12 March 2009

Get-DaysInMonth.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     Displys number of days in a particular month.   
  4. .DESCRIPTION 
  5.     This scrips uses System.DateTime to determine, then 
  6.     display, the numbe of days in some months. 
  7. .NOTES 
  8.     File Name  : Get-DaysInMonth.ps1 
  9.     Author     : Thomas Lee - tfl@psp.co.uk 
  10.     Requires   : PowerShell V2 CTP3 
  11. .LINK 
  12.     http://www.pshscripts.blogspot.com 
  13. .EXAMPLE 
  14.     PSH [C:\foo]: . 'C:\foo\Get-daysinmonth.ps1' 
  15.     There are 31 days in July 2001 
  16.     There are 28 days in February 1998 
  17.     There are 29 days in February 1996 
  18.     There are 31 days in August 1950 
  19. #> 
  20.  
  21. ## 
  22. # Start of script 
  23. ## 
  24.  
  25. # Create variables representing months 
  26. $July      = 7 
  27. $February  = 2 
  28. $August    = 8 
  29.  
  30. # daysInJuly should be 31. 
  31. $daysInJuly = [System.DateTime]::DaysInMonth(2001, $July
  32. "There are $daysinjuly days in July 2001" 
  33.  
  34. # DaysInFeb should be 28 because the year 1998 was not a leap year. 
  35. $daysInFeb = [System.DateTime]::DaysInMonth(1998, $February
  36. "There are $daysinfeb days in February 1998" 
  37.  
  38. # daysInFebLeap gets 29 because the year 1996 was a leap year. 
  39. $daysInFebLeap = [System.DateTime]::DaysInMonth(1996, $February
  40. "There are $daysinfebleap days in February 1996" 
  41.  
  42. # An august year indeed. 
  43. $daysInAugust = [System.DateTime]::DaysInMonth(1950, $August
  44. "There are $daysinAugust days in August 1950" 
  45. # End of Script 

No comments: