|
Answer» hey all,
I've got 2 txt file's with time and date in them.
I'd LIKE to create a scheduled task to run 10min before the time and on the date in the txt file's to start another batch file. (yet to be written!!)
The time is in 24 format and the date is in 18.7.2008 format.
I'm just trying to get the time formated to the correct format first, i.e 2000 becomes 1900 + 2009 becomes 1909 and so on....
this is what I have so far...
Code: [Select]@echo off
set /p aptime=<aptime.txt echo %aptime%
pause
set hour=%aptime:~0,2% set min=%aptime:~3,2% echo %hour% = hour echo %min% = min if "%min%" lss "9" (set /a hour=%hour% -1) set /a newmin=%min% -10 echo %hour% = hour echo %min% = min
pause set newtime=%hour% %min% echo %newtime% pause
Sadly this isn't' working anyway here what it should.
anyone got any ideas???
Remember that if SET /A encounters a number beginning with 0 (ZERO) it considers that number to be in Octal (base eight) format. If %aptime% is set to 09.08 then %hour% will be set to 09 and %min% to 08. When SET /A in your IF statement attempts to decrement %hour% by 1 it meets 09 which is invalid in Octal (valid DIGITS are 0 thru' 7) and the IF statement fails. So how to get rid of the leading zero's if they exist - I suggest:
set /a hour=1%aptime:~0,2%-100 (this is just one way of set /a min=1%aptime:~3,2%-100 dropping leading zero's)
If %hour% is set to 0 (zero) and you decrement this by 1 then %hour% will be set to -1, not 23 which is probably what you want. The same situation arises with %min%, if it's already set to <10 then %newmin% will be set to a negative number.
When manipulating time in the 24-hour format, hours must be treated as base 24 (valid values 0 thru' 23) and minutes as base 60 (valid values 0 thru '59) so after decrementing you must check for a value <0 and if it exists add the appropriate base, either 24 for hours or 60 for minutes. If you increment then you must check for a value >the base and if it exists deduct the base.
Good luckCheers for the reply,
I've made a change to my server so that the times that come in are going to be either, 0800, 1100, 1400, 1700 and 2000.
basically, I can get round the whole issue of dropping the leading 0, by using 5 if STATEMENTS;
Code: [Select]if "%time%" == "0800" (set time=0750 && exit) and so on...
I haven't tested it yet, but it should work without any issues. I hope...
|