#navi(../)

* 本日が月末かどうかを判定するPowerShellスクリプト [#c811551b]
Get-Dateコマンドレットを利用して本日が月末かどうかの判定をするPowerShellスクリプトを書いてみました。

#contents
#htmlinsertpcsp(win-top.html,win-sp.html)

* 関連記事 [#c354547c]
-[[Get-Dateコマンドレットで前日、翌日、前月、翌月などの日付を取得する方法>PowerShell/Get-Dateで前日、翌日、前月、翌月などの日付を取得する方法]]
-[[PowerShellで文字列の日時をDateTimeオブジェクトにする方法>PowerShell/文字列の日時をDateTimeオブジェクトにする方法]]

* 月末判定のPowerShellスクリプト [#a310a422]
月末判定を行うPowerShellスクリプトのサンプルを記します。

以下の処理は、本日に+1日し、翌日の日付が1日だった場合、月末として判定しています。

#ref(eom.ps1)
 if ( (Get-Date).AddDays(1).Day -eq 1 ) {
   Write-Host (Get-Date).ToString('yyyy-MM-dd') is end of month.
 }
 else {
   Write-Host (Get-Date).ToString('yyyy-MM-dd') is *NOT* end of month.
 }


* 月末判定PowerShellスクリプトの実行結果 [#x7ddac72]
月末と月末以外の日付で月末判定スクリプトを実行してみたときの出力です。

- 月末ではない
 PS C:\Users\sakura\Desktop> (Get-Date).ToString('yyyy-MM-dd')
 2012-05-23
 
 PS C:\Users\sakura\Desktop> C:\Users\sakura\Desktop\eom.ps1
 2012-05-23 is *NOT* end of month.

- 月末である
 PS C:\Users\sakura\Desktop> (Get-Date).ToString('yyyy-MM-dd')
 2012-05-31
 
 PS C:\Users\sakura\Desktop> C:\Users\sakura\Desktop\eom.ps1
 2012-05-31 is end of month.

#htmlinsertpcsp(win-btm.html,win-sp.html)

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS