I Need To Make A Change With My IT Support! Call (225) 706-8414

Get the date/time in your Windows batch files

You are running Windows 2003+ and need to get the date and time into variables in your DOS batch files.

Solution

This is very easy to do now in a batch script.

set year=%date:~10,4%
set month=%date:~4,2%
set day=%date:~7,2%
set hour=%time:~0,2%
if %hour% lss 12 set hour=0%hour:~1,1%
set min=%time:~3,2%
set sec=%time:~6,2%
echo %year%
echo %month%
echo %day%
echo %hour%
echo %min%
echo %sec%

Concerned About Cyber Attacks?

CLICK HERE >

Want to Migrate to the Cloud?

CLICK HERE >
Office 365

Ready to Experience Microsoft Office 365?

Want the latest IT news directly in your inbox? Subscribe now!