Link to home
Start Free TrialLog in
Avatar of sirbounty
sirbountyFlag for United States of America

asked on

time adjustment still not working...

Already asked, but I'm still having a few 'hiccups' in my code.


I'm running the command:
  net time \\server ^|find /i "Local"

against a list of servers.

Three conditions will be returned.

1) No "Local" will exist, since the server is already local to my timezone.
2) Local Time (GMT-X:00) at \\server is mm/dd/yyyy HH:mm will be returned if it's offset from GMT
3) Local Time (GMT) at \\server is mm/dd/yyyy HH:mm will be returned if it is in GMT



I need to take the current local time and add 3 minutes to it to schedule my job.  
I'm aware of SOON, but it doesn't suit my purpose.

The time must be returned in the format of HH:mm
I'll be adding :ss to it.

I need to make sure that the hour and minute have a preceeding zero (0) if it's less than 10.
Additionally, if adding 3 minutes takes minutes over 59, then obviously I need to increment the hour, and subtract 60 from the new minutes.  Same applies if the hour exceeds 23..

Here's what I have (haphazardly) created:

set strTime=00:00
set srv=%1
for /f "tokens=10 delims=\/ " %%a in ('net time \\%srv% ^|find /i "Local"') do set strTime=%%a
::if no time is returned, strTime will still be 00:00, so simply make strTime the equivalent of the local time, stripping off seconds
if %strTime%==00:00 set strTime=%time:~0,8%

set strHour=%strTime:~0,2%  
set strMinute=%strTime:~3,2%

set /a strMinute=%strMinute%+3

if %strHour% LSS 10 set strHour=0%strHour:~1%
if %strMinute% LSS 10 set strMinute=0%strMinute:~1%

if %strMinute% GEQ 60 (
  set /a strMinute=%strMinute%-60
  set /a strHour=%strHour%+1
  If %strHour% GTR 23 set strHour=00
)

set strNewTime=%strHour%:%strMinute%:00
SOLUTION
Avatar of cwwkie
cwwkie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cwwkie
cwwkie

> if %strMinute% LSS 10 set strMinute=0%strMinute:~1%

to make this work both when strMinute is " 9" and "9", you can do this:

set /a strMinute=%strMinute%
if %strMinute% LSS 10 set strMinute=0%strMinute%
I'd recommend the following changes:

set /a strHour=1%strHour% - 100
set /a strMinute=1%strMinute% - 100 + 3

echo %strMinute%

if %strMinute% GEQ 60 (
  set /a strMinute-=60
  set /a strHour+=1
  if %strHour% GTR 23 set /a strHour=0
)

if %strHour% LSS 10 set strHour=0%strHour%
if %strMinute% LSS 10 set strMinute=0%strMinute%
> set /a strHour=1%strHour% - 100
> set /a strMinute=1%strMinute% - 100 + 3

because sirbounty said in a previous question (http:Q_21779179.html) there was a whitespace before the number, that won't work, because the result would be for example:
     set /a strHour=1 9 - 100
So I think those lines should be like this instead:

set /a strHour=%strHour%
set /a strMinute=%strMinute% + 3
Avatar of sirbounty

ASKER

I had tried to implement your little 100 trick Steve, but it hadn't worked out for me.
Works so far now - I'll wait till after the hour to try again, just to be sure.
Thanx.
If you want to make sure that you don't have white space you can always call a subroutine:

set strHour= 10

call :REMOVESPACE strHour %strHour%

echo strHour=%strHour%

goto :EOF

:REMOVESPACE

set %1=%2

goto :EOF
Had to make some additional code modifications (not on this) and I'm waiting to deploy the new code with the updated script...should be sometime today (I hope).
That's "my" question Dushan911... : |

Steve/cwwkie - I've found two problems so far.
One was when trying to run it just after midnight last night - it had a problem with the 00 in hour.
I think it was the same error I'm seeing now though...

Here,
for /f "tokens=10 delims=/\ " %%x in ('net time \\%srv% ^|find /i "Local"') do set strLclTime=%%x
strLclTime is equal to
8:32:45

strHour= 8
strMin=32
(notice the white space in front of 8, but not 32)

Thus
set /a strHour=1 8 - 100
fails to work.

I haven't tried your last post Steve.  Trying it now, and I'll post back shortly...
Nope...
Now hh of 08 ends up being calculated as:

18-100 which equates to negative 82 - not a valid hour...<sigh>
Any ideas?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Will try on Monday Steve - thanx.