@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=