LoginSignup
0
0

More than 5 years have passed since last update.

[PowerShell]ある日付から何日か前の日付を取得する To Get Date before X days From Some Day.

Posted at

2019年5月3日から122日前の日付を取得します。
$dt1に2019年5月3日を代入します。この時VBAで使われるような#5/3/2019#のような日付リテラルで囲んだりシングルクォーテーション、ダブルクォーテーションで囲まなくてよいようです。
念のためデータの型(Type)を強制するため[DateTime]をつけています
関数としては、ある日付の何日か前はAddDaysに▲の日数を入れて求めます。

[datetime]$dt1 = get-date -date 2019/5/3 ;[datetime]$dt2= $dt1.AddDays( -122);Write-Host $dt2
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0