Discussion:
Setting System Time N Hours Back
(too old to reply)
Saucer Man
2021-01-23 17:17:28 UTC
Permalink
I'm looking to set the system time back a certain number of hours.
Would anyone know how to do that in a batch file?
Zaidy036
2021-01-23 20:30:48 UTC
Permalink
I'm looking to set the system time back a certain number of hours. Would
anyone know how to do that in a batch file?
If it is to run a program look at
<https://www.nirsoft.net/utils/run_as_date.html>

reset your time zone
<https://www.windows-commandline.com/set-time-zone-from-command-line/>
Zaidy036
2021-01-24 22:45:38 UTC
Permalink
Post by Zaidy036
Post by Saucer Man
I'm looking to set the system time back a certain number of hours.
Would anyone know how to do that in a batch file?
If it is to run a program look at
<https://www.nirsoft.net/utils/run_as_date.html>
Using above will not affect your system time but only the program or
batch it runs. Anything else requires resetting your system time after
running your batch.

Output of "Time" command may be manipulated like any other variable:

Following will insure hour is not a single digit:
SET _TX=%Time%
IF "%_TX:~1,1%"==":" SET _TX=0%_TX%
SET Hr=%_TX:~0,2%
SET /A NewHr=%Hr% [+-] x

If min:sec not important than use Nirsoft above with %NewHr%:00:00
Saucer Man
2021-01-25 18:55:13 UTC
Permalink
Post by Zaidy036
Post by Zaidy036
Post by Saucer Man
I'm looking to set the system time back a certain number of hours.
Would anyone know how to do that in a batch file?
If it is to run a program look at
<https://www.nirsoft.net/utils/run_as_date.html>
Using above will not affect your system time but only the program or
batch it runs. Anything else requires resetting your system time after
running your batch.
SET _TX=%Time%
IF "%_TX:~1,1%"==":" SET _TX=0%_TX%
SET Hr=%_TX:~0,2%
SET /A NewHr=%Hr% [+-] x
If min:sec not important than use Nirsoft above with %NewHr%:00:00
Thanks for tip about this program. In this instance, I'm not looking to
run a program with an earlier time. I am looking to set my system time
back a certain number of hours. Your other suggestion about changing
the time zone may be suitable.

JJ
2021-01-24 12:23:15 UTC
Permalink
Post by Saucer Man
I'm looking to set the system time back a certain number of hours.
Would anyone know how to do that in a batch file?
Yes, but it'll depend on your date and time format.
Saucer Man
2021-01-24 15:46:59 UTC
Permalink
Post by JJ
Post by Saucer Man
I'm looking to set the system time back a certain number of hours.
Would anyone know how to do that in a batch file?
Yes, but it'll depend on your date and time format.
The date is in M/D/YEAR and the time is in 12 Hour format.
Fin Tres Nueve Dos
2021-01-24 19:13:40 UTC
Permalink
Post by JJ
Post by Saucer Man
I'm looking to set the system time back a certain number of hours.
Would anyone know how to do that in a batch file?
Yes, but it'll depend on your date and time format.
Check this. It is not depending on date and time format

:: Example of using the function
@ECHO OFF & SETLOCAL

CALL :GetLocalDateTime CurrentTime

ECHO Current date and time is [%CurrentTime%]

ENDLOCAL & EXIT /B 0


:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::
:: Return local date and time with format 'yyyymmddhhmmss.ffffff+mmm'.
::
:: Rear '+mmm' is the UTC time offsets in minutes.
::
:GetLocalDateTime {Return_variable}

FOR /F "tokens=1* delims==" %%a IN ('wmic OS GET LocalDateTime /VALUE ^| find "="') DO SET "%~1=%%b"

EXIT /B 0
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Saucer Man
2021-01-24 20:46:22 UTC
Permalink
Post by Fin Tres Nueve Dos
Post by JJ
Post by Saucer Man
I'm looking to set the system time back a certain number of hours.
Would anyone know how to do that in a batch file?
Yes, but it'll depend on your date and time format.
Check this. It is not depending on date and time format
:: Example of using the function
@ECHO OFF & SETLOCAL
CALL :GetLocalDateTime CurrentTime
ECHO Current date and time is [%CurrentTime%]
ENDLOCAL & EXIT /B 0
:: Return local date and time with format 'yyyymmddhhmmss.ffffff+mmm'.
:: Rear '+mmm' is the UTC time offsets in minutes.
:GetLocalDateTime {Return_variable}
FOR /F "tokens=1* delims==" %%a IN ('wmic OS GET LocalDateTime /VALUE ^| find "="') DO SET "%~1=%%b"
EXIT /B 0
Thanks. I see it is returning the correct time and UTC offset. If I
wanted to set the system time back 4 hours for example, how would I use it?
Loading...