Forum Discussion

rodrigueA's avatar
rodrigueA
Occasional Contributor
8 years ago

Keyword test - How set up variable with current hour

Hello,

 

For 1 of my keyword tests, I must set a variable(integer format)  with current hour (without minutes) in 24H format (ex : If I launch the test at 08H30 PM I want set variable with 20).

I try to choose code expression : GetHours(Time) in action Set variable value but it doesn't work.

If somebody has an idea.

 

Thanks a lot for your help.

 

Best regards,

  • Hi,

     

    You can use the "GetHours" Method for this. Please find the sample script below. You can call it from your KDT or create the same operations in KDT. 

     

    [JScript]

    function DateTest() {
       date = aqDateTime.Now();
       h = aqDateTime.GetHours(date);
       Log.Message(h);
    }

  • YuriPeshekhonov's avatar
    YuriPeshekhonov
    SmartBear Alumni (Retired)

    Hi,

     

    You can use the "GetHours" Method for this. Please find the sample script below. You can call it from your KDT or create the same operations in KDT. 

     

    [JScript]

    function DateTest() {
       date = aqDateTime.Now();
       h = aqDateTime.GetHours(date);
       Log.Message(h);
    }