Printer Version Table of Contents Project Home Page
.FAQ.........: How do I put FDATE's output into an environment variable?
.DISCUSSION..:
There are two methods. One uses a temporary batch file. The other uses enhanced features of the FOR command.

Method 1 should work on all versions of Windows. But note that it will not work if the person running your batch file does not have WRITE permissions on the directory where you want to put junk.bat. If this is a problem, then you can work around it by creating the temporary batch file in a directory where you are sure that the user does have WRITE permissions -- for example, in the root directory of the C: drive: c:\junk.bat.

.EXAMPLE.....:
@echo off
:: put Fdate output into an environment variable called "date1"

:: ------------------------------------------------------------
:: METHOD #1 -- Use a temporary batch file
:: ------------------------------------------------------------
FDATE /Ff /ofull /p"set date1=" >junk.bat
call junk.bat
echo It is now %date1%

:: cleanup
del  junk.bat
set date1=

.DISCUSSION..:
An alternative work-around is to use Method 2, if you are using a version of Windows that supports it.

Method 2 uses enhanced features of the FOR command that should be available on Windows NT, Windows 2000, XP, and later versions of Windows. Note that the parameter "tokens=*" is required is the Fdate output contains multiple words -- as a general practice, you should always specify it. In using Method 2, you may have to watch carefully to make sure that any strings in quote-marks are closed by matching quote-marks of the correct type.

.EXAMPLE.....:
@echo off
:: put Fdate output into an environment variable called "date1"

:: ------------------------------------------------------------
:: METHOD #2 -- use the enhanced FOR command features
:: This method should work on Windows NT, Windows 2000, and XP
:: ------------------------------------------------------------
for /f "tokens=*" %%v in ('FDATE /Ff /C"~~Y-~M-~D (~W)"') do set date1=%%v
echo Today is %date1%

:: cleanup
set date1=