Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Setting System Time N Hours Back

41 views
Skip to first unread message

Saucer Man

unread,
Jan 23, 2021, 12:17:26 PM1/23/21
to
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

unread,
Jan 23, 2021, 3:30:51 PM1/23/21
to
On 1/23/2021 12:17 PM, Saucer Man wrote:
> 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/>

JJ

unread,
Jan 24, 2021, 7:23:17 AM1/24/21
to
On Sat, 23 Jan 2021 12:17:28 -0500, Saucer Man wrote:
> 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

unread,
Jan 24, 2021, 10:46:55 AM1/24/21
to
The date is in M/D/YEAR and the time is in 12 Hour format.

Fin Tres Nueve Dos

unread,
Jan 24, 2021, 2:13:41 PM1/24/21
to
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

unread,
Jan 24, 2021, 3:46:20 PM1/24/21
to
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?

Zaidy036

unread,
Jan 24, 2021, 5:45:40 PM1/24/21
to
On 1/23/2021 3:30 PM, Zaidy036 wrote:
> On 1/23/2021 12:17 PM, Saucer Man wrote:
>> 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

unread,
Jan 25, 2021, 1:55:08 PM1/25/21
to
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.
0 new messages