JSI Tip 4835. The Universal Date Parser, modified to also work with Windows XP.

Jerold Schulman

February 12, 2002

1 Min Read
ITPro Today logo in a gray background | ITPro Today


In tip 3481, I introduced the Universal Date Parser.

UnivDate.bat allowed parsing of the current date into its' month, date, and year components, regardless of the date format or language used.

When Windows XP was introduced, Microsoft changed the output of the date /t command to be different from the previous versions of Windows NT. Windows NT 4.0 and Windows NT 5.0 (Windows 2000) output a day, followed by your configured short date format. Windows NT 5.1 (Windows XP) dropped the outputting of the day, requiring changes to every batch script that parses the current date.

NOTE: If you open a CMD prompt and type date and then press Enter, you can see that the second line of theoutput does contain a model of the date format. Borrowing a technique from tip 1986 How can I get an accurate time in a batch job, we can use the echo.|date syntax to press the enter key for us.

NOTE: See How can I insure that a year, month, and day contain 4,2, and 2 digits, respectively?

I have modified UnivDate.bat to contain:

@echo offset $tok=1-3for /f "tokens=1 delims=.:/-, " %%u in ('date /t') do set $d1=%%uif "%$d1:~0,1%" GTR "9" set $tok=2-4for /f "tokens=%$tok% delims=.:/-, " %%u in ('date /t') do ( for /f "skip=1 tokens=2-4 delims=/-,()." %%x in ('echo.^|date') do (    set %%x=%%u    set %%y=%%v    set %%z=%%w    set $d1=    set $tok=))



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like