1.

Solve : Comparing two character dates?

Answer»

Ok last problem (I think).

I am comparing two 12 digit numbers (YYYYMMDDHHMM), the GTR doesn't seem to work as it runs a job that is scheduled for next year.

FYI, My O/S and Date Format are in my signature file at the end of my posts.


runjob.bat

echo %1
5.200709111259.DON.j155.UserSecurity.job

REM Set up the current date and time
set CURRENTHOUR=%TIME:~0,2%
if %CURRENTHOUR% LSS 10 set CURRENTHOUR0%CURRENTHOUR%
set CURDATETIME=%DATE:~6,4%%DATE:~3,2%%DATE:~0,2%%CURRENTHOUR%%TIME:~3,2%

REM Check the run time of the job
set JOBFILE=%1
set RUNDATETIME=%JOBFILE:~2,12%

echo %RUNDATETIME%, %CURDATETIME%
200709111259, 200610162028

REM Run the job if the date/time is less than current date/time
if %RUNDATETIME% GTR %CURDATETIME% goto END

REM Rename the job so it runs and doesn't get picked up again
move %1 %1.bat

REM Run the job
call %1.bat > %QUEUES%\%QUEUE%\logs\%1

REM Archive the job
move %1.bat %1.done

:END



This process does not go to END it CONTINUES to execute the script
I think the command PROMPT can only handle 32-bit integers.  Assuming that is the CASE, you have to deal with numbers that are between 0 and 4294967295 (or may.  Your date STRING / number of 12 characters is probably just too big.

Maybe try chopping off some insignicicant digits (3 to be safe) from the front and / or back of the number?

Maybe try
if %RUNDATETIME:~2,9% GTR %CURDATETIME:~2,9% goto END
Just be aware that that will only work as long the CURDATETIME and the RUNDATETIME don't get past the year 2042 (assuming my theory about the 32-bit unsigned integers is correct)If you have Python:
Code: [Select]import sys,time,os
jobname = sys.argv[1] #get job name
getdate = jobname[2:14] #get 200709111259
current = time.time() #get current time in seconds
convert = time.strptime(getdate,"%Y%m%d%H%M%S")  
rundate = time.mktime(convert) #convert 200709111259 to seconds
if rundate < current:
        print "Run the job because less than current date/time"
        os.rename(jobname, jobname + ".bat") #rename to .bat
        os.system(jobname + ".bat") #run job

Thanks again GuruGary. That worked.
Of course by the time 2042 comes around....I won't care about this system, as I will be 79.
If this system is still RUNNING....I pitty the fool who has to maintain it....lol



Discussion

No Comment Found