Skip navigation

Category Archives: scripts

A colleague of mine asked me how to make a batch file script that will put time stamp on his file/s on a Windows environment. Given that this is easy in Linux systems, I was quite amused in doing it on a Windows system. Flashback of old school scripting in DOS era came as I try to recall the batch file commands and environment restrictions in Windows.

Finally, after about half an hour, I came up with a batch file script that will put date and time stamp to a file. Here’s the short batch file for it…. (copy-paste it on a text editor and save the file with .bat or .cmd extension)

@echo off
for /f "tokens=1-3 delims=:." %%a in ("%time%") do set timestamp=%%a%%b%%c
for /f "tokens=1-3 delims=/." %%a in ("%date%") do set datestamp=%%a%%b%%c
echo >"testfile-%datestamp%-%timestamp%".txt

This code can be integrated on other batch files to stamp log files or rename files with timestamp or datestamp information.