(view source code of sortdate2.bat as plain text)
@ECHO OFF
:: Windows NT 4 or later onlyIF NOT "%OS%"=="Windows_NT" GOTO Syntax
:: No command line arguments requiredIF NOT [%1]==[] GOTO Syntax
:: Keep variables localSETLOCAL
:: Store current date in a variable in default Locale formatFOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET DATE=%%B
ECHO It is %DATE% today
:: Store current date in a variable in YYYYMMDD format:: Export registry settings to a temporary fileSTART /W REGEDIT /E %TEMP%.\_TEMP.REG "HKEY_CURRENT_USER\Control Panel\International"
:: Read the exported dataFOR /F "tokens=1* delims==" %%A IN ('TYPE %TEMP%.\_TEMP.REG ^| FIND /I "iDate"') DO SET iDate=%%B
FOR /F "tokens=1* delims==" %%A IN ('TYPE %TEMP%.\_TEMP.REG ^| FIND /I "sDate"') DO SET sDate=%%B
DEL %TEMP%.\_TEMP.REG
:: Remove quotesSET iDate=%iDate:"=%
SET sDate=%sDate:"=%
:: Parse today's date depending on registry's date format settingsIF %iDate%==0 FOR /F "TOKENS=1-4* DELIMS=%sDate%" %%A IN ('DATE/T') DO (
SET Year=%%C
SET Month=%%A
SET Day=%%B
)IF %iDate%==1 FOR /F "TOKENS=1-4* DELIMS=%sDate%" %%A IN ('DATE/T') DO (
SET Year=%%C
SET Month=%%B
SET Day=%%A
)IF %iDate%==2 FOR /F "TOKENS=1-4* DELIMS=%sDate%" %%A IN ('DATE/T') DO (
SET Year=%%A
SET Month=%%B
SET Day=%%C
):: Remove the day of week if applicableFOR %%A IN (%Year%) DO SET Year=%%A
FOR %%A IN (%Month%) DO SET Month=%%A
FOR %%A IN (%Day%) DO SET Day=%%A
:: Today's date in YYYYMMDD formatSET SortDate=%Year%%Month%%Day%
ECHO For sorting purposes: %SortDate%
:: DoneENDLOCAL & SET SortDate=%SortDate%
GOTO:EOF
:SyntaxECHO.
ECHO SortDate, Version 3.10 for Windows NT 4 / 2000 / XP
ECHO Save date and "sorted" date in environment variables.
ECHO.
ECHO Usage: %0
ECHO.
ECHO This batch file will always display the same results,
ECHO independent of "International" settings.
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
ECHO Adapted for Windows XP with help from Kailash Chanduka
page last modified: 2025-10-11; loaded in 0.0084 seconds