Using dates in batch files to rename files with yesterday's date

Posted on 2008-11-06
Medium Priority
Last Modified: 2012-06-21
I have a script that gives me today's date in the following format 20081106. I need to change the script so that I get the date in the following format 081106.
Also, I would like another variance of the script to get yesterday's date.
@echo on
for /f "tokens=2-4 delims=/ " %%a in ('DATE/T') do set Date=%%c%%a%%b
echo %date%

Open in new window

Question by:nsc_tech
  • 2

Assisted Solution

wwnosal earned 2000 total points
ID: 22900686
This solves your firs problem:
@echo on
for /f "tokens=2-4 delims=/ " %%a in ('DATE/T') do set Date=%%c%%a%%b
echo %date:~-6%

Open in new window


Accepted Solution

wwnosal earned 2000 total points
ID: 22900693
And this should solve your second problem:

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month17 days, 6 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question