SASAKESystems

Helping you to bring your Colours.

PowerShell Get-Date de 2011/04/00.

PowerShellでは、引き算、足し算が使える。
プログラミングの知識が浅い自分でも、簡単に使用が出来る。
Get-date - 1 = 0400と表示され、スクリプトエラーに。
エラーになって、初めて別の方法を探す。

昨日を表示するには、Get-Dateより先に、計算式を仕込んであげる。

$Yesterday = get-date -uformat %Y%m%d ((get-date).adddays(-1))

(-1)の部分を変えるだけで、求める日付が設定できる。

これが先月としたいなら、daysを、monthに変えるだけ。

$LastMonth = get-date -uformat %Y%m%d ((get-date).addmonth(-1))

他には、下記リンクのように様々に変更すればいいだけ。
Windows PowerShell Tip of the Week  More Fun with Dates (and Times)

0 コメント: