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

Posted on 2008-11-06
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
    LVL 6

    Assisted Solution

    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

    LVL 6

    Accepted Solution

    And this should solve your second problem:

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    This article was inspired by a question here at Experts Exchange ( The requirements stated in that question are (1) reduce the file size of a large number of…
    Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    755 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now