msgbartop
A chronological documentation test project, nothing serious, really!
msgbarbottom

02 Oct 2007 Formatting date in MS-DOS batch file

I needed to make a simple MS-DOS backupscript in Windows XP today and the files were supposed to be stored in folders named by the current date, ISO style.

I ended up formatting the date using the following command

echo %date:~6,8%-%date:~3,2%-%date:~0,2%

Output

2007-10-02

The script

@echo off
REM Declare variables
Set TODAYSDATE=%date:~6,8%-%date:~3,2%-%date:~0,2%
Set DATADRIVE=c:
Set DATAFOLDER=Temp
Set BACKUPDRIVE=c:
Set BACKUPFOLDER=Backup

REM Make Backup folders
mkdir %BACKUPFOLDER%
mkdir %BACKUPFOLDER%%TODAYSDATE%

REM Copy files to todays backup folder
xcopy /e /v /c /f /h /z /y %DATADRIVE%%DATAFOLDER%* %BACKUPDRIVE%%BACKUPFOLDER%%TODAYSDATE%

The script creates a backup folder and copies files from a datafolder and stores them in todays backupfolder.

Do note that the date command prints the date in the format DD.MM.YYY, 02.10.2007

This script has been run on a daily basis through Windows Scheduler.

Tags: , ,

Posted by

07 May 2007 Stille systemklokke

# date --set='+2 minutes'
# date --set='+2 hours'

Tags:

Posted by

17 Feb 2007 Listing files by date, ISO style

ls -lgot --time-style=long-iso

Tags:

Posted by