Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Input system date as a variable in a batchfile

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
In a batch file, is there a way out to store the date variable as the file name. ie, the file name should be ddmmyyyy. say i generate the directory listing on a daily basis, this file name should be 24092002.xxx. when i generate the file the next day the same should be saved as 25092002.xxx. Help me out please
 
Hi

I found this which may help you. Just need to modify it.

Calculating yesterday's date on Win9x (DOS batch).

so this batch will do it:
===== BATCH SCRIPT BEGIN =====
@echo off
for /F "tokens=2,3,4 delims=/- " %%a in ("%DATE%") do (
set M=%%a
set D=%%b
set Y=%%c
)

:: Set today's date format
set TODAY=%M%%D%%Y%

set /A D=D-1
if not "%D%"=="0" goto dateend
set /A M=M-1
if not "%M%"=="0" goto keepyear
set /A Y=Y-1
set M=12
:keepyear
for %%a in (2 4 6 9 11) do if "%M%"=="%%a" set D=30
if "%D%"=="0" set D=31

:dateend
if "%D:~1,1%"=="" set D=0%D%
if "%M:~1,1%"=="" set M=0%M%

:: Set yesterday's date format
set YESTERDAY=%M%%D%%Y%

for %%? in (M D Y) do set %%?=

echo YESTERDAT=%YESTERDAY%
echo TODAY=%TODAY%
===== BATCH SCRIPT END =====

Watch out for line wrapping!

That script will get today's and yesterday's date into the variables %TODAY% and %YESTERDAY%. The format is MM/DD/YYYY, but that can be changed (read commented lines).

That script is only for NT systems. In order to do such a thing in Win9x, I would store today's date to be used tomorrow, instead of calculating yesterday's date.

 
Hi

You could also do

TimeDate | SetTimeDate

Then %date% and %time% are available from the environment.

Whichever you find simpler will work.

The Date returned has / but I know the author and could easily get one done without the slashes. Hey, forgot, source is there too, so you can remove the slashes any time.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top