

These batch files set the variable TIME to the time they are executed. The same tricks work for DATE as well, you only need to make some minor adjustments. The definition and use of a linefeed variable is discussed at Explain how dos-batch newline variable hack works. Setting EOL to a linefeed is described in detail at HOW TO: FOR /F Disabling EOL or using a quote as delim. Using an LF variable instead of embedding linefeeds within the FOR statement is just an extension of the technique.
I have a batch script for backing up databases. I echo the%time% that script starts and then the%time% it ends to a log file. Even though the script takes 5 minutes to backup our databases the end time is identical to the start time. @echo off:: Credentials preconfigured for backup-operator net use y: 172. Download Zero Hour 1.06 Patch Software. 16.104. Garrett Ace 150 Manuale Italiano. 201 Backups:: Date in format YYYY.MM.DD set DATESTAMP=%DATE:~-4%.%DATE:~3,2%.%DATE:~0,2% set LOCAL_DIR=F: Backups set EXTERN_DIR=Y: DB3:: Output all to txt >'%LOCAL_DIR%SQLBackups-%DATESTAMP%.txt' ( echo. Echo ------------------------------------------------------------------------------ echo -- Starting SQL Backups%date%%time% -- echo ------------------------------------------------------------------------------ echo.:: Backup and Copy loop setlocal enabledelayedexpansion for%%i in ( DB1 DB2 DB3 DB4 etc. ) do ( set DATABASENAME=%%i set BACKUPFILENAME=!LOCAL_DIR!!DATABASENAME!-!DATESTAMP!bak echo. Echo ------------------------------------------------------------------------------ echo -- Backing Up Database!DATABASENAME!
To local-- echo ------------------------------------------------------------------------------ echo. Sqlcmd -E -S DB3 -d master -Q 'BACKUP DATABASE [!DATABASENAME!] TO DISK = '!BACKUPFILENAME!' WITH DESCRIPTION = 'Full backup [!DATABASENAME!]', CHECKSUM, INIT, COMPRESSION' echo. Dxwnd Ms there.
Echo -- Copying!DATABASENAME! Backup to external-- robocopy!LOCAL_DIR!!EXTERN_DIR!!DATABASENAME!-!DATESTAMP!bak echo. Echo --!DATABASENAME! ) endlocal:: Delete files older than -d days from local forfiles -p%LOCAL_DIR% -s -m *.bak -d '-180' /C 'cmd /c echo @path & del @path' forfiles -p%LOCAL_DIR% -s -m *.txt -d '-180' /C 'cmd /c echo @path & del @path' echo. Echo -- Script Complete%date%%time% -- echo. ) robocopy%LOCAL_DIR%%EXTERN_DIR% 'SQLBackups-%DATESTAMP%.txt' net use y: /delete.
@ ECHO OFF CLS rem ============================================================== rem === Store Various Date/Time Elements Into Variables rem ============================================================== rem rem Created On: 24 May 1999 rem By: Andrew S. Baker rem rem Updated On: 06 May 2004 rem By: Andrew S. Baker rem rem ============================================================== rem OS Required: NT4 or Higher rem rem Non-Native Utilities Required: (for some scripts) rem Resource Kit..
Rem ==============================================================::: These scripts obtain various elements of the date and time::: for use in naming files -- particularly logs.:::::: A number of different approaches are taken, some with the::: native only tools, and some with the use of Resource Kit::: tools.:::::: NOTE: The parsing of date variables in all of the date-related::: scripts in this archive is dependent on the Regional::: Settings in the Control Panel.