Concatenate system date to a file

Posted on 2005-05-16
Last Modified: 2010-04-19
Hi Experts, currently I am scheduling a command-line zip task every midnight. I want to zip to the file with name as where yyyymmdd is the system year, month and day. Please advice me on how could I achieve this using batch file command line.

Question by:bpyeo
    1 Comment
    LVL 82

    Accepted Solution

    The current date is in the environment variable %date%.
    That comes in a rather unhandy format, as you can't use neither the slash nor does it have the correct sequence you want.
    You can use a "for /f" command to do that; if necessary, depending on your date format, adjust the date delimiter used ("/") and the order in which the tokens are assigned:

    for /f "tokens=1-3 delims=/" %%a in ("%date%") do (
      set mm=%%a
      set dd=%%b
      set yyyy=%%c
    set BackupFile=backup_%yyyy%%mm%%dd%

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    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

    I guess it is not common knowledge to most Wintel engineers/administrators: If you have an SNMP-based monitoring system in your environment (and it's common to have SNMP or Syslog) it's reasonably easy to enable monitoring of the Windows Event logs,…
    Learn about cloud computing and its benefits for small business owners.
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    737 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

    17 Experts available now in Live!

    Get 1:1 Help Now