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


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 the output 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 off
set $tok=1-3
for /f "tokens=1 delims=.:/-, " %%u in ('date /t') do set $d1=%%u
if "%$d1:~0,1%" GTR "9" set $tok=2-4
for /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=))


Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish