JSI Tip 0559 - DATE math.

Jerold Schulman

June 7, 1998

1 Min Read
ITPro Today logo


In tip 531, we created JSIToday to parse today's date and JSIExpDT to parse a user's password expiration date.

You can configure when Windows NT issues a password expiration warning by using tip 141.

In tip 721, we built JSIDateM, a generalized date math routine.

If you want to issue your own password expiration warning, you need the ability to do DATE math. Create JSIExpire.bat:

Usage: JSIExpire "UserName" Days otify.bat

@echo off set PWDX=NIf %1

"" goto syntaxset User=%1set User=%User:"=%if "%2"

"" goto syntaxset agea=%2set /a agen=%agea%if "%agea%"

"%agen%" goto dates:syntax@echo JSIExpire UserName Days otify.batgoto end :datesif %3

"" goto syntaxif not exist %3 goto syntaxcall jsitodayset TYMD=%TDYY%%TDMM%%TDDD%net user %1 /domain | find /i "Password expires" > "%temp%jsiexpire_%User%.log"for /f "tokens=1,2,3,4,5* delims=/ " %%i in ('type "%temp%jsiexpire_%User%.log"') do set XMM=%%k&set XDD=%%l&set XYY=%%mREM If your date format is DD-MM-YY, use: REM for /f "tokens=1,2,3,4,5* delims=- " %%i in ('type "%temp%jsiexpire_%User%.log"') do set XDD=%%k&set XMM=%%l&set XYY=%%mif /i  "%XMM%" EQU "Never" goto endcall JSIDateM %XYY% %XMM% %XDD% - %2if %AYMD% GTR %TYMD% goto end :Notify set PWDX=Y call %3 %1 %2 :end if exist "%temp%jsiexpire_%User%.log" del /q "%temp%jsiexpire_%User%.log"


Sample Notify.bat

 @echo The password for account %1 expires on %NYY%-%NMM%-%NDD% which is within %2 days of %TDYY%-%TDMM%-%TDDD% (Today minus %2 is %XYMD%) REM You can use any form of notification that you wish: REM Net Send %1 Your password expires on the day %NDD% of month %NMM% in year %NYY%. Please change it today. REM or use a freeware command line mailer like Blat.

JSIExpire also returns a PWDX evironment variable with the following values:
N=Does not expire within Days days.
Y=Does expire within Days days.

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