Skip navigation

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

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 off
call univdate
call day %yy% %mm% %dd% daynumb daytext
set TDDAY=%daytext%
set TDYY=%yy%
set TDMM=%mm%
set TDDD=%dd%
set /a mm=10%mm%%%100
if %mm% LSS 10 set TDMM=0%mm%
set /a dd=10%dd%%%100
if %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 
set XYY=19%XYY% 
You can then test if the password never expires:

if /i %XMM% EQU never goto Never

Hide 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.