Hello. To the most questioned FAQ about batch scripting from this forum, how to get system's current date into a variable without the separators, I've been giving this solution for DOS and Win9x:
:: Get current date into variable without separators
@echo off
echo.EXIT|%COMSPEC%/K PROMPT SET %%1=$D$_|FIND " "> %TEMP%.\T1.BAT
type nul> %TEMP%.\T2.DAT
for %%? in (e10D''3B e110''3B w q) do echo %%?>> %TEMP%.\T2.DAT
DEBUG %TEMP%.\T1.BAT < %TEMP%.\T2.DAT > nul
call %TEMP%.\T1.BAT DATE
:: Next line defines date format. The values generally are:
:: %%1=Week day %%2=Month %%3=Date %%4=Year (4 digits)
:: Those could change, depending mainly on the COUNTRY
:: command (from config.sys).
echo SET DATE=%%2%%3%%4> %TEMP%.\T1.BAT
call %TEMP%.\T1.BAT %DATE%
for %%? in (T1.BAT T2.DAT) do del %TEMP%.\%%?
echo DATE=%DATE%
Although that method works fine on most cases, it depends on the country settings from config.sys. The known date formats for DOS are:
MM/DD/YYYY
DD/MM/YYYY
YYYY/MM/DD
The separators may change ("/" "-" or ".") but the formats are those. The script only works as intended with the first format, which is used on US (country code 001). If the date format is the second one, used on several countries such as UK and Brazil, the month and date tokens appear swapped on the script, and if the date format is the third one, the variables get broken, all screwed.
So, though it works on many situations, it's not 100% sure to work as intended, so it's not that good.
I've done some research and found another method, developed by Laura Fairhead, which uses a little assembler script to get the date and solves all the problem. Here's it:
:: Get system's current date into multiple variables
@echo off
if "%1"=="GoTo" goto %2
echo e180 BF 07 01 B4 04 CD 1A E8 02 00 89 CA E8 00 00> %temp%.\t1.src
echo e18F 86 D6 88 D0 D4 10 0D 30 30 86 C4 AB 47 C3>> %temp%.\t1.src
for %%? in (rip 180 g w q) do echo %%?>> %temp%.\t1.src
echo SET %%1=XX XX XX XX> %temp%.\t2.bat
DEBUG %temp%.\t2.bat < %temp%.\t1.src > nul
call %temp%.\t2.bat _
%0 GoTo parse %_% MM DD YC YY
:parse
set %5=%1
shift
if not "%5"=="" goto parse
for %%? in (t1.src t2.bat) do del %temp%.\%%?
set _=
The variables are:
DD - date
MM - month
YC - year century (first two digits from year)
YY - year (last two digits from year)
That method is already updated on my FAQ.
I'm sorry for distributing that faulty method on the past months (maybe years). However, I did warn users of its limitations on the source of the script itself (but I didn't consider the third date format, which brokes the variables).
That's all. BTW, I've just updated 10 FAQs from my page, and more improovements are coming soon.
-- Leonardo Pignataro - Secret_Doom --
secret_doom@hotmail.com
www.batch.hpg.com.br
_________________________________________________________________________