Start Task when date arrived

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
fuxing
Posts: 2
Joined: 22 Jan 2020 05:11

Start Task when date arrived

#1 Post by fuxing » 22 Jan 2020 05:25

Hallo!

I have a problem with a date check within a batch file.

I have a file under "C:\Windows" called "apsch" where i enter a date until nothing should happen. But when the date has passed i want the batch file to rename another file.
My Problem is that it only looks for the day, but ignores the month and year.

What is working:
When the "validthru-date" is further than 9 days the batch file closes immediately
When the "validthru-date" is within the next 9 days a message appears

What is not working:
eg: Today is the 22nd of Jan.
When i enter the 21st of Feb. (validthru=21.02.2020) it says that this day has already passed.

Hope anyone can help me!

Thanks
Jürgen

"apsch" (from C:\Windows)

Code: Select all

validthru=20.01.2020
"apro_datenbank.bat" (my batch file itself)

Code: Select all

@echo off
mode con:cols=100 lines=1
title Heute ist der %date%
cls
if not exist "C:\Windows\apsch" goto valid
for /f "tokens=1,2 delims==" %%a in (C:\Windows\apsch) do (if %%a==validthru set validthru=%%b)
if %validthru% lss %date% (goto invalid) else (goto valid)

:invalid
cls
cd\
cd aprokassa
cd Executeables
ren borlndmm.dll locked
taskkill /IM apro_bon.exe
cls
ping 127.0.0.1 -n 2
cls
::start apro_bon.exe
color 0c
mode con:cols=90 lines=11
title Heute ist der %date%
cls
echo;
echo;
echo    **********************************************************************************
echo;
echo                      Ihre Lizenz ist am %validthru% abgelaufen.
echo                      Bitte wenden Sie sich an unseren Support!
echo;
echo    **********************************************************************************
echo;
cmd /k @echo off 


:valid
cls
cd\
cd aprokassa
cd Executeables
ren locked borlndmm.dll
cls
tasklist /FI "IMAGENAME eq apro_bon.exe" 2>NUL | find /I /N "apro_bon.exe">NUL
if "%ERRORLEVEL%"=="0" (echo Program is running) else (start C:\aprokassa\Executeables\apro_bon.exe)
cls
echo WScript.Echo DateAdd("d", 9, Now) > "C:\aprosystem\days.vbs"
for /f %%a in ('cscript //nologo "C:\aprosystem\days.vbs"') do set NewDate=%%a   
::echo %NewDate%
if %validthru% lss %NewDate% (goto message) else (goto end)

:message
cls
color 0a
mode con:cols=90 lines=11
title Heute ist der %date%
cls
echo;
echo;
echo    **********************************************************************************
echo;
echo                        Ihre Lizenz ist gueltig bis %validthru%
echo           Bitte wenden Sie sich, fuer eine Verlaengerung, an unseren Support!
echo;
echo    **********************************************************************************
echo;
cmd /k @echo off 



:end
exit

fuxing
Posts: 2
Joined: 22 Jan 2020 05:11

Re: Start Task when date arrived

#2 Post by fuxing » 22 Jan 2020 07:14

I Found a solution!

I changed the format of the date into yyyymmdd:

Code: Select all

call :date_to_number %date% date1
call :date_to_number %validthru% date2

if %date1% gtr %date2% (goto invalid) else (goto valid)

goto :eof
:date_to_number
setlocal
if "%~1" EQU "" goto :eof
for /f "tokens=1,2,3 delims=." %%D in ("%~1") do (set "the_date=%%F%%E%%D")
endlocal & if "%~2" neq "" (set %~2=%the_date%) else echo %the_date%
goto :eof
and compared this values

But thanks eventhough!!!

penpen
Expert
Posts: 1771
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Start Task when date arrived

#3 Post by penpen » 22 Jan 2020 19:08

Depending on your implementation of determining "within the next 9 days", your solution might not give you the message that you wnated it to appear (for example if the actual date were the "31.01.2020" and the date you are comparing to were "01.02.2020").
You could use jTimestamp.bat or an own custom jscript/bat hybrid to do the date computations (inlcuding comparisons).

penpen

Edit: Fixed link.

Eureka!
Posts: 69
Joined: 25 Jul 2019 18:25

Re: Start Task when date arrived

#4 Post by Eureka! » 22 Jan 2020 19:29

Be aware that "apsch" is not a part of Windows and might be missing on other systems.

Alternative: SCHTASKS.exe
With this (command-line) utility you can create scheduled tasks to run any program. SCHTASKS /? for more info.

Post Reply