このエントリーをはてなブックマークに追加


本日が月末かどうかを判定するPowerShellスクリプト

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


関連記事

月末判定のPowerShellスクリプト

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

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

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スクリプトの実行結果

月末と月末以外の日付で月末判定スクリプトを実行してみたときの出力です。

  • 月末ではない
    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.


添付ファイル: fileeom.ps1 358件 [詳細]

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2016-02-16 (火) 22:57:14