Some technical stuff
2008-08-24Timestamp YYYY-MM-DDTHHMMSS in einer Windows Shell
To get a correctly formatted timestamp within a Window batchfile (CMD, BAT), you do have to overcome a little problem.+
The environment variable %TIME% does show hours before 10am with a leading space (allthoug %DATE% does show days < 10 with a leading zero.
To get a valid timestamp (e.g. for naming logfiles) a batchfile has to check for this special case.
here you find an example code:
set DATUM_FORMATIERT=%DATE:~10,4%-%DATE:~4,2%-%DATE:~7,2% set NOW=%TIME% set VORNULL=NEIN if "! !"=="!%NOW:~0,1%!" set VORNULL=0 if %VORNULL%==0 set STUNDE=0%NOW:~1,1% if not %VORNULL%==0 set STUNDE=%NOW:~0,2% set UHRZEIT_HHMMSS=%STUNDE%%NOW:~3,2%%NOW:~6,2% set TIMESTAMP=%DATUM_FORMATIERT%T%UHRZEIT_HHMMSS%
(c) Wolfgang Wagner, Vienna, 2008