1
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.

備忘録:DOSコマンドで日付を出力する

Last updated at Posted at 2021-08-22

フィールドSEという職業柄、訪問した客先でバッチファイルを作成することがある。簡単なBATを書く場合でもログに日付を出力したいが、よく忘れるので備忘録として記載する。
日付8桁

コマンドプロンプト
d>set YYYYMMDD=%date:~0,4%%date:~5,2%%date:~8,2%
d:\>echo %YYYYMMDD%
20210822

西暦4桁

コマンドプロンプト
d:\>set YYYY=%date:~0,4%
d:\>echo %YYYY%
2021

月2桁

コマンドプロンプト
d:\>set MM=%date:~5,2%
d:\>echo %MM%
08

日2桁

コマンドプロンプト
d:\>set DD=%date:~8,2%
d:\>echo %DD%
22

fontsフォルダのDIRリストをログに出力する。

コマンドプロンプト
d:\>set YYYYMMDD=%date:~0,4%%date:~5,2%%date:~8,2%
d:\>cd c:\windows\fonts
c:\Windows\Fonts>dir /s >d:\test_%YYYYMMDD%.txt

結果は以下のように出力される。
image.png

1
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
1
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?