PDQ Library:  Create File Name with Today's Date

You must already know how to use batch commands to use this page. I accept
no responsibility for any accidents you have using batch commands.

Batch Commands - Windows 7

The following is a test program that works in Windows 7. This page was created because most batch programs for creating date variables in Windows XP do not work in Windows 7. Copy this text into a file called test.bat and run it to see if it displays today's date in 3 formats. (If it doesn't, do a google search for "batch programs for date".)

@echo off
echo Date Format: dd-mm-yy
@echo %DATE:~6,4%-%DATE:~3,2%-%DATE:~0,2%
echo Date Format: yy-mm-dd
@echo %DATE:~0,2%-%DATE:~3,2%-%DATE:~6,4%
echo Date Format: yymmdd
@echo %DATE:~0,2%%DATE:~3,2%%DATE:~6,4%

Batch Program Example

The following is a batch program for Windows 7 that uses 7z, the command line version of the free compression utility 7-Zip (download) to create a .zip file. (ou may use any compression utility that has a command line option.) This is an example - you must edit it to suit your requirements. You may also create a dated folder name, and then create another command to copy files into it.

  1. Set a variable "Date" with your choice of format (e.g. December 20, 2009 becomes 091220).
  2. Set a variable "Folder" to the source folder (not required, but helpful for long path names).
  3. Compress all files in the source folder with extension .doc into a file called Docs-101220.zip on a backup drive. The switches a and tzip instruct 7z to add the files and create an archive in the .zip format.
@echo off
echo Zip up all DOC files in this folder:
set Folder="C:\Users\Pat\My Documents"
echo.
rem Set variable for date in format yymmdd
set Date=%DATE:~0,2%%DATE:~3,2%%DATE:~6,4%
echo.
rem Run 7-Zip to create a dated ZIP file in drive H
"C:\Program Files\7-Zip\7zFM.exe" a -tzip H:\Docs_%Date% %Folder%\*.doc*
TOP back