@echo off REM generate SQL script to get date in correct format: echo select 'set my_date=' + str_replace(convert(char(20),getdate(),102),'.','-') >%TEMP%\getDate_yyyy-MM-dd.sql echo go >>%TEMP%\getDate_yyyy-MM-dd.sql REM run the SQL script to generate a simple, temporary batch file: isql -U username -P password -i %TEMP%\getDate_yyyy-MM-dd.sql | findstr set >%TEMP%\set_my_date.bat REM run the temporary batch file, which will set an environment variable, 'MY_DATE', to contain the date: call %TEMP%\set_my_date.bat REM clean up del /q %TEMP%\set_my_date.bat del /q %TEMP%\getDate_yyyy-MM-dd.sql REM this is where you'd actually put code that uses the date, like: REM md c:\backup\%MY_DATE% REM copy c:\mystuff\*.* c:\backup\%MY_DATE%