Forum Discussion

JennyH11's avatar
JennyH11
Frequent Contributor
6 years ago
Solved

Setting the system date to Today + 2

Hi 

 

I am trying to work out how to change the system date based on todays date to the date in 2 days time. I need it to be dynamic as the rest of the dates in the test are dynamic. I realise that this might complicate it as it will need to calculate based on number of days in month etc.

 

Is there a way to implement this in a keyword test?

 

So far I've read a lot of information regarding how to implement but only in Scripts. I'm wondering if I am missing something obvious in the more familar (to me) kwtests.

 

The best I've come up with is to use Run Code Snippet operation and the code: aqDateTime.SetSystemDateTime(aqDateTime.AddDays.Today(), 1). Whilst it saved OK, it did not change the system date. I'm probably doing it quite wrong and would appreciate any advice.

 

Many thanks,

Jenny

 

ps - main article read so far:

https://support.smartbear.com/testcomplete/docs/scripting/working-with/dates/vbscript.html#Tomorrow

  • Hi Jenny,

     

    a) Your code snippet does not look correct. I would expect this:

    aqDateTime.SetSystemDateTime(aqDateTime.AddDays(aqDateTime.Today(), 2))

     

    b) Documentation for the .SetSystemDateTime() method mentions that in order to succeed, the method mus be executed with admin privileges.

     

2 Replies

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi Jenny,

     

    a) Your code snippet does not look correct. I would expect this:

    aqDateTime.SetSystemDateTime(aqDateTime.AddDays(aqDateTime.Today(), 2))

     

    b) Documentation for the .SetSystemDateTime() method mentions that in order to succeed, the method mus be executed with admin privileges.

     

    • JennyH11's avatar
      JennyH11
      Frequent Contributor

      Thank you Alex!

       

      I'm glad I was on the right track! :)