@echo off
rem -------------------------------------------
rem The name of this batch file is date-var.bat
rem -------------------------------------------
rem
rem ****************************************************
rem Run this batch file from the command line to see the
rem effects of the commands within.
rem ****************************************************
rem
rem ====================================================
rem
rem Remember :
rem When running variables from a batch file
rem you need two '%' signs in the command.
rem
rem i.e., echo %%DATE%%
rem
rem But when running a variable directly from the
rem command prompt (line), you only need
rem one '%' sign in the command.
rem
rem i.e., c:\>echo %DATE%
rem
rem ====================================================
rem
echo.
echo.
echo ///////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
echo.
echo This email thread provided the commands to
echo produce the date variable I wanted.
echo.
echo http://www.computing.net/windows2000/wwwboard/forum/59489.html
echo.
echo This batch file runs under win2k (maybe winxp or winnt).
echo.
echo \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\///////////////////////////////
rem
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set year=%%c
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set month=%%a
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set day=%%b
set TODAY=%year%-%month%-%day%
rem echo %TODAY%
echo.
echo.
echo The following commands build the 'date variable' called "TODAY".
echo.
echo for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set year=%%c
echo for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set month=%%a
echo for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set day=%%b
echo set TODAY=%%year%%-%%month%%-%%day%%
echo.
echo Now ... TODAY = %TODAY%
echo.
pause
echo.
echo With this date variable set, you can now create
echo files and directories with the date in it's name.
echo.
echo This command :
echo.
echo sample-file-name-%%TODAY%%.txt
echo.
echo Will produce this result :
echo.
echo sample-file-name-%TODAY%.txt
rem Running this batch file will show the results
echo.
pause
echo.
echo. Now add the time to the output:
for /f "tokens=1 delims=: " %%h in ('time /T') do set hour=%%h
for /f "tokens=2 delims=: " %%m in ('time /T') do set minutes=%%m
for /f "tokens=3 delims=: " %%a in ('time /T') do set ampm=%%a
set NOW=%hour%-%minutes%-%ampm%
rem echo %NOW%
rem
rem the output from the 'time /t' command is different on
rem WinXp than it is on Win2K.
rem WinXp = 08:58 PM
rem Win2K = 8:58p
rem So, when using WinXP, the extra variable 'ampm' is
rem created for the AM or PM designation.
rem
echo.
echo for /f "tokens=1 delims=: " %%h in ('time /T') do set hour=%%h
echo for /f "tokens=2 delims=: " %%m in ('time /T') do set minutes=%%m
echo for /f "tokens=3 delims=: " %%a in ('time /T') do set ampm=%%a
echo set NOW=%%hour%%-%%minutes%%-%%ampm%%
echo.
echo sample-file-name-%%TODAY%%-%%NOW%%.txt
echo.
echo sample-file-name-%TODAY%-%NOW%.txt
rem Running this batch file will show the results
echo.
pause
echo.
echo.
rem testing .........................
rem time /t
rem -------------------------------------------
rem You'll find these GNU utilities for Win32
rem handy for the commands below:
rem http://unxutils.sourceforge.net/
rem -------------------------------------------
rem echo.
rem echo.
echo grepping the variables from the 'set' command:
echo.
set | grep -i -e hour -e minutes -e ampm
set | grep -i -e year -e month -e "^day"
echo.
rem touch bob.txt
rem copy bob.txt bob-%today%_%now%.txt
rem ls | grep bob
rem rm -f bob*
rem echo.
rem ls
pause