WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

DOS

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

BAT file that can check a date

 Keywords:  DOS BAT DATE 

This DOS BAT file can test to see if a particular date has occurred yet or not. This could be used to enable or disable precesses on a certain date.
  REM  Hard parts by William Allen (NgReply@mayfly13.fsnet.co.uk)

  @ECHO OFF
  IF (GOTO:)==(%1) %1%2 (Subroutine handler)

  :: ECHO the check date here in YYYY/MM/DDb format:
  :: (This demo uses 15 May 2002=2002/O5/15b)
  ECHO.2002/05/15b>%TEMP%.\_CHECK

  :: Call Subroutine to return: C=Century Y=Year MO=Month D=Day
  CALL %0 GOTO: _DTM

  :: We then append the current date in same format+"a"
  ECHO.%C%%Y%/%MO%/%D%a>>%TEMP%.\_CHECK
  FOR %%V IN (C Y MO D) DO SET %%V=
  TYPE %TEMP%.\_CHECK| find /v /n "">%TEMP%.\_CHECK

  :: If current date has passed check date, this won't invert line order
  TYPE %TEMP%.\_CHECK|sort /+4|find /v /n ""|find "[1][2]">NUL
  DEL %TEMP%.\_CHECK
  IF ERRORLEVEL 1 GOTO PASSED
  ECHO. We haven't passed your check date yet
  GOTO EOF

  :PASSED (your check date)
  ECHO. We have passed your check date
  regedit.exe /s file.reg 

  GOTO EOF (=Subroutine section below=)

  :_DTM (Usage: CALL %0 GOTO: _DTM)
  %COMSPEC%/c %0 GOTO: 2_DTM ECHO. REM:|debug|find ":">%TEMP%.\_DTM.BAT
  %COMSPEC%/c %0 GOTO: 2_DTM REM: ECHO.|debug %TEMP%.\_DTM.BAT>NUL
  CALL %TEMP%.\_DTM.BAT %0 GOTO: 1_DTM
  DEL %TEMP%.\_DTM.BAT
  GOTO EOF

  :1_DTM
  FOR %%V IN ("C=%9" "Y=%8" "MO=%5" "D=%4") DO SET %%V
  GOTO EOF (=Debug scripting follows=)

  :2_DTM
  %3e100 e8 0 0 80 c3 2 88 dc cd 1a 89 97 1e 1 89 8f 22 1 c3
  FOR %%F IN (g "d120 127" q) DO %3%%F
  FOR %%F IN ("e100'CALL %%1 %%2 %%3'" w q) DO %4%%F

  :EOF (End-of-file)

Article ID:   W15937
File Created: 2004:03:30:15:41:46
Last Updated: 2004:03:30:15:41:46