この記事は2008/02/21にわんくまブログで書いたものです。
指定した年月の最終日を取得する関数を作成してみました。
Get-LastDay.ps1
#=============================================================================== # Get-LastDay: 指定した年月の最終日を取得する # # パラメータ: # $Year: 年(省略した場合は現在の年) # $Month: 月(省略した場合は現在の月) # # 使用例1(年月指定) # PS > Get-LastDay 2008 2 # # 使用例2(年月省略) # PS > Get-LastDay # # copyright HIRO's.NET(http://hiros-dot.net/) #=============================================================================== function global:Get-LastDay { Param ([int]$Year = $(Get-Date).Year, [int]$Month = $(Get-Date).Month) return [System.DateTime]::DaysInMonth($Year, $Month) }
関数本体よりコメントのほうが長い....
ポイント
DateTime構造体のDaysInMonthは、指定した年月が持つ日数を返します。
それをreturnしているだけです...
補足
パラメータを省略した場合は、当月の最終日を返します。
Theme design by Jelle Druyts
Pick a theme: BlogXP business calmBlue Candid Blue dasBlog dasblogger DirectionalRedux Discreet Blog Blue Elegante essence Just Html MadsSimple Mobile Mono Movable Radio Blue Movable Radio Heat nautica022 orangeCream Portal Project84 Project84Grass Slate Sound Waves Tricoleur useit.com Voidclass2 BlogXP business calmBlue Candid Blue dasBlog dasblogger DirectionalRedux Discreet Blog Blue Elegante essence Just Html MadsSimple Mobile Mono Movable Radio Blue Movable Radio Heat nautica022 orangeCream Portal Project84 Project84Grass Slate Sound Waves Tricoleur useit.com Voidclass2
Powered by: newtelligence dasBlog 2.0.7226.0
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2009, HIRO
E-mail