0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

バッチファイルで PowerShell を使って曜日を得る

Last updated at Posted at 2020-10-30

曜日を取得する DOS コマンドは無いので PowerShell の機能を使う。
文字化けするときは UTF-8 じゃなく Shift-JIS (ANSI) で保存。
(Windows 10, Windows 7 等)

dayofweek.bat


@echo off
echo.

powershell "exit ((Get-Date).adddays(-1).dayofweek.value__)"
echo 昨日: %errorlevel%

powershell "exit ((Get-Date).dayofweek.value__)"
echo 今日: %errorlevel%

powershell "exit ((Get-Date).adddays(1).dayofweek.value__)"
echo 明日: %errorlevel%

set tm=2021/1/1
powershell "exit (([DateTime]'%tm%').dayofweek.value__)"
echo 指定日 %tm% : %errorlevel%

echo.
pause
goto :eof


 %errorlevel%
 0 ... 日曜日
 1 ... 月曜日
 2 ... 火曜日
 3 ... 水曜日
 4 ... 木曜日
 5 ... 金曜日
 6 ... 土曜日

実行例

昨日: 5
今日: 6
明日: 0
指定日 2021/1/1 : 5

続行するには何かキーを押してください . . .
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?