Forum Discussion

mgroen's avatar
mgroen
Frequent Contributor
11 years ago

capture current date and time in a string

I would like to capture the date and time (at the moment of test execution), and post it in a message box in our tested web application.



I prefer to use Keyword mode testing. But I use code snippets whenever needed.



What would be the best and most clean approach, to capture the date (in format DD/MM/YY) and time (hh:mm:ss)  at the moment the test is run?



thanks!



  • mgroen's avatar
    mgroen
    Frequent Contributor
    Seems very useful but it does not show anything.

    Do I need to check something to use the AqDateTime object?
  • You could do something like this


    var timestamp = Now();


    Log.Message(aqConvert.DateTimeToFormatStr(timestamp,"%m/%d/%Y %H:%M:%S"));

  • Marsha_R's avatar
    Marsha_R
    Icon for Champion Level 3 rankChampion Level 3
    See attached for the keyword test version
  • mgroen's avatar
    mgroen
    Frequent Contributor
    Using the following tekst in the log message doesn't work:

    "Now:" & aqDateTime.Now()



    result is empty message in the log



    however, if I create a variable of type string and first set the value of this variable to aqDateTime.Now and after that display the value of this variable in the log it is working correctly.



    Is this correct behaviour of TC ?

  • Marsha_R's avatar
    Marsha_R
    Icon for Champion Level 3 rankChampion Level 3
    aqDateTime.Now() is not a string so it can't print out



    see my attachment above for an example of the conversion