Reputation: 319
How do I determine the value of variable ecg in the batch file given below ?
for /f "Tokens=1-4 Delims=/ " %%i in ('date /t') do set ecg=%%l%%j%%k
Upvotes: 1
Views: 73
Reputation: 41224
To get a timestamp: Wmic creates a robust version that doesn't depend on the PC settings, like %date% and date /t do. Win XP Pro and above.
:: time and date stamp YYYYMMDD, HHMMSS and YYYY-MM-DD_HH-MM-SS
@echo off
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set dt=%%a
set datestamp=%dt:~0,8%
set timestamp=%dt:~8,6%
set YYYY=%dt:~0,4%
set MM=%dt:~4,2%
set DD=%dt:~6,2%
set HH=%dt:~8,2%
set Min=%dt:~10,2%
set Sec=%dt:~12,2%
set stamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%
echo stamp: "%stamp%"
echo datestamp: "%datestamp%"
echo timestamp: "%timestamp%"
pause
Upvotes: 0
Reputation: 4750
an easy way is to add the following line
echo.ecg=%ecg%
By way of explanation... %%i would be the first token (day of week) which you are not using %%j is the 2nd token (month) %%k is the 3rd token (day of month) %%l is the 4th token (year) So ecg will contain something like 20130612... depending on the date format your PC is set to use.
Upvotes: 2