Date change using Batch Files

I am running monthly queries and exporting the results as .csv files.  I am trying to create a batch file that changes the file name by adding the current month and year at the end of the file name and then moving the file to the appropriate folder.  (ex. NST_ALMachineryException.csv= NST_ALMachineryException_Feb08.csv).  
MarkRJacksonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lee W, MVPTechnology and Business Process AdvisorCommented:
I would recommend changing your datecode a little for ease of coding and sorting...

In the batch file, use:

REN NST_ALMachineryException.csv NST_ALMachineryException_%date:~-4%-%date:~4,2%.csv

that will result in a file name of NST_ALMachineryException_2008-02.csv  (Year first, then Month)

If you insist on keeping it month first than year, then you will need to use:
REN NST_ALMachineryException.csv NST_ALMachineryException_%date:~4,2%-%date:~-4%.csv

If you insist on keeping the month name, then you will need to create a series of IF statements...

IF "%date:~4,2%"="01" set MMM=Jan
IF "%date:~4,2%"="02" set MMM=Feb
IF "%date:~4,2%"="03" set MMM=Mar
IF "%date:~4,2%"="04" set MMM=Apr
IF "%date:~4,2%"="05" set MMM=May
IF "%date:~4,2%"="06" set MMM=Jun
IF "%date:~4,2%"="07" set MMM=Jul
IF "%date:~4,2%"="08" set MMM=Aug
IF "%date:~4,2%"="09" set MMM=Sep
IF "%date:~4,2%"="10" set MMM=Oct
IF "%date:~4,2%"="11" set MMM=Nov
IF "%date:~4,2%"="12" set MMM=Dec
REN NST_ALMachineryException.csv NST_ALMachineryException_%MMM%-%date:~-2%.csv
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MarkRJacksonAuthor Commented:
Thanks for the reply.  One thing that was missing is an extra "=" in the IF commands.
0
Lee W, MVPTechnology and Business Process AdvisorCommented:
Your right - I was typing in a mix of VB and batch... sorry about that.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.