Set Clock back for hours

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
carmine
Posts: 15
Joined: 18 Nov 2013 13:12

Set Clock back for hours

#1 Post by carmine » 10 Feb 2014 04:04

Hi,

I have this codes which does the clock back in minutes i need to set back for 2 hours. How to do that.

Code: Select all

@echo off
set /a mm=%time:~3,2%
set /a hh=%time:~0,2%
if %mm% lss 5 (set /a hh=%hh%-1) & set /a mm=%mm%+60
if %hh% equ -1 set /a hh=23
set /a mm=(%mm%-5)
time %hh%:%mm%
(set mm=) & set hh=

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Set Clock back for hours

#2 Post by foxidrive » 10 Feb 2014 04:21

What do you want to happen if it is 1am? Will it have to change to 11pm the day before?

carmine
Posts: 15
Joined: 18 Nov 2013 13:12

Re: Set Clock back for hours

#3 Post by carmine » 10 Feb 2014 04:46

foxidrive wrote:What do you want to happen if it is 1am? Will it have to change to 11pm the day before?


Thanks for response.

Infact the script will be run under schedule task at 11:45 P.M. To delay the date (day) change.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Set Clock back for hours

#4 Post by foxidrive » 10 Feb 2014 04:49

carmine wrote:Infact the script will be run under schedule task at 11:45 P.M. To delay the date (day) change.



Then all you need to do is this for that one time:

Code: Select all

time 21:45


Try it at the command line.

carmine
Posts: 15
Joined: 18 Nov 2013 13:12

Re: Set Clock back for hours

#5 Post by carmine » 10 Feb 2014 05:05

Hi,

Tricky, Thanks foxidrive.

Is there any trick to sync the time with server any tricky way.

Thanks

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Set Clock back for hours

#6 Post by foxidrive » 10 Feb 2014 05:16

In Windows 8 there is this in the help for

Code: Select all

w32tm /? |more
and it should be in earlier version too.

w32tm /resync [/computer:<computer>] [/nowait] [/rediscover] [/soft]
Tell a computer that it should resynchronize its clock as soon
as possible, throwing out all accumulated error statistics.
computer:<computer> - computer that should resync. If not
specified, the local computer will resync.
nowait - do not wait for the resync to occur;
return immediately. Otherwise, wait for the resync to
complete before returning.
rediscover - redetect the network configuration and rediscover
network sources, then resynchronize.
soft - resync utilizing existing error statistics. Not useful,
provided for compatibility.

carmine
Posts: 15
Joined: 18 Nov 2013 13:12

Re: Set Clock back for hours

#7 Post by carmine » 10 Feb 2014 05:39

Hi,

Thanks a lot.

Post Reply