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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Script Library
 Batch File Date
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

2 Posts

Posted - 12/01/2008 :  21:07:59  Show Profile  Reply with Quote
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

Aged Yak Warrior

591 Posts

Posted - 12/03/2008 :  05:51:31  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000