Ask a Question

efficient way of changing system date

SOLVED
m_essaid
Valued Contributor

efficient way of changing system date

Hi,

I musn't be the only one who need to change its system datetime while executing tests...

I tried two ways, this one :

net time /set /yes

and this one :

w32tm /resync

with the command line, but both don't work 100% of the time.

 

Does anyone has any workaround ?

 

Thank you

 

6 REPLIES 6
BenoitB
Community Hero

Stop the W32Time service before changing date/time because unless that the time will be resync automatically after short time.

 

You can stop it using cmd in administrator mode with NET STOP W32Time /YES

To change machine date/time use DATE and TIME in cmd

If not working with NET STOP you can use SC object.

Un sourire et ça repart

Wamboo
Community Hero

Hi,

 

What OS are You using?

 

Take a look at this article, maybe this can help You?

 

https://www.wikihow.com/Change-the-Computer-Time-and-Date-Using-the-Command-Prompt

 

inside cms console, You can use a command like: "HH:MM:SS AM/PM" or the similar one for date-time. On windows ofc.

tristaanogre
Esteemed Contributor

We've actually been successful using aqDateTime.SetSystemDateTime.

 

https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqdatetime/setsystemdateti...

 

It requires TestComplete/TestExecute to be run with admin privileges and, as noted above, you might want to stop any network time synchronization to make sure you can preserve your expected time.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available

Hi all,

 

Seems to be the cleanest way to resolve my problem ! Thank you !

I'm on windows 10.

I already have a clue for preventing the PC resetting the date. For this key :

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Parameters

I set "Type" to "NoSync".

Thus the domain controller leave my machine alone.

m_essaid
Valued Contributor

How do you get back to current time Robert ?

tristaanogre
Esteemed Contributor

What we did is, before we changed the time, we captured the current date and time (using the "Get" method) and stored it in a variable.  Then, we just used that as part of the next "Set" statement to restore.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
cancel
Showing results for 
Search instead for 
Did you mean: