Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Script Library
 Batch File Date

Author  Topic 

reading01
Starting Member

2 Posts

Posted - 2008-12-01 : 21:07:59
Hello - I new to this forum so please let me know if I am posting this question in the wrong area or if batch file questions are off topic.

I am trying to append current date to file via batch. The below script is working although, in the past this same script has worked as expected. This time I am running the script on an EU server, perhaps the date format needs to be reformatted? Suggestions greatly appreciated.

cd cd C:\***yourfilepath here***


REM *** Create variables for mm, dd, yyyy ***

FOR /f "tokens=2" %%i in ('date /t') do set thedate=%%i
set mm=%thedate:~0,2%
set dd=%thedate:~3,2%
set yyyy=%thedate:~6,4%


REM *** use date to build XYZ filename ***

set bfile=XYZ_%yyyy%%mm%%dd%.PDF


REM *** rename reports ***

ren XYZ XYZ_%yyyy%%mm%%dd%.PDF

darkdusky
Aged Yak Warrior

591 Posts

Posted - 2008-12-03 : 05:51:31
The date format on you machine may be different to mine (mine is dd/mm/yyyy) so this batch file makes 2 files with 2 date formats, choose works on your machine.

cd C:\temp
rem --flips order of dates as my PC i.e cba
for /f "tokens=1-3 delims=/ " %%a in ('date /t') do set _date=%%c%%b%%a
rem --keeps same order of dates as my PC i.e abc
for /f "tokens=1-3 delims=/ " %%a in ('date /t')do set _ukdate=%%a%%b%%c
copy XYZ.pdf XYZ_uk_%_ukdate%.pdf
ren XYZ.pdf XYZ_%_date%.pdf
Go to Top of Page
   

- Advertisement -