JSI Tip 0531 - How do I parse a date into month, day, and year?

Jerold Schulman

May 14, 1998

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


NOTE: Starting with Windows XP, Date /t no longer returns the day. JSIToday.bat has be modified to call UnivDate.bat and DAY.bat.

1. To parse todays date in a batch and return environment variables TDDAY, TDMM, TDDD, and TDYY, call JSIToday which contains:

@echo offsetlocalcall univdatecall day %yy% %mm% %dd% daynumb daytextset TDDAY=%daytext%set TDYY=%yy%set TDMM=%mm%set TDDD=%dd%set /a mm=10%mm%%%100if %mm% LSS 10 set TDMM=0%mm%set /a dd=10%dd%%%100if %dd% LSS 10 set TDDD=0%dd%endlocal&set TDDAY=%TDDAY%&set TDYY=%TDYY%&set TDMM=%TDMM%&set TDDD=%TDDD%

2. To parse the logged on user's password expiration date in batch and return environment variables XMM, XDD, and XYY, call JSIExpDT which contains:

 @echo off net user %UserName% /domain | find /i "Password expires" > "%temp%jsiexpdt_%UserName%.log" for /f "tokens=1,2,3,4,5* delims=/ " %%i in ('type "%temp%jsiexpdt_%UserName%.log"') do set XMM=%%k&set XDD=%%l&set XYY=%%m REM If your date format is DD-MM-YY, use: REM for /f "tokens=1,2,3,4,5* delims=- " %%i in ('type "%temp%jsiexpdt_%UserName%.log"') do set XDD=%%k&set XMM=%%l&set XYY=%%m if /i "%XMM%" EQU "Never" goto end if "%XYY%" GTR "97" goto Y19 set XYY=20%XYY% goto end :Y19 set XYY=19%XYY% :end

You can then test if the password never expires:

if /i %XMM% EQU never goto Never



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