Date and Time in .bat

I will skip right to the good stuff.

Here are some easy Date/Time variables for a batch file.

[code lang=”powershell”]
@echo off
set d=%date:~7,2%
set DD=%date:~0,3%
set m=%date:~4,2%
set YY=%date:~10,4%
set y=%date:~12,2%
set H=%time:~0,2%
set i=%time:~3,2%
set s=%time:~6,2%
set ms=%time:~9,2%
echo d: %d%
echo DD: %DD%
echo m: %m%
echo YY: %YY%
echo y: %y%
echo H: %H%
echo i: %i%
echo s: %s%
echo ms: %ms%

Will Output

[code lang=”text”]
d: 24
DD: Wed
m: 02
YY: 2010
y: 10
H: 14
i: 36
s: 32
ms: 18

Hope it helps.

This entry was posted in bat. Bookmark the permalink.