Ask a Question

keyword test; variable of type object; store DateTime in keyword variable - javascript

Occasional Contributor

keyword test; variable of type object; store DateTime in keyword variable - javascript

Hi, I am trying to store a COMDateTime object into a keyword local variable (as shown in the below pictures). Is this now allowed? When I run the below code, I get a 'type mismatch' error.









Community Hero

I don't seen COMDateTime as a variable type here


Try specifically defining fileTimeStamp as a Date/Time type and see if that resolves the mismatch.



[Community Hero]
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
Trusted Contributor

You will have to convert the timestamp to an integer value, which will represent number of seconds (Epoch)

function main()
    var time = timestamp(); // epoch time
    Log.Message("Epoch: " + time);
    var date = new Date(time); // date time
    Log.Message("Date: " + date);    

function timestamp()
    var fileTimeStamp = aqFile.GetLastWriteTime("C:\\Temp\\Book1.xlsx");
    Log.Message("File: " + fileTimeStamp);
    var date = new Date(fileTimeStamp);
    return date.getTime(); // return epoch time


Occasional Contributor

thank you all for the help. Let me try this out and see if it works. 

Occasional Contributor

You both are correct. It is unusual to me. I can store a Javascript Date into the object but I cannot store a TestComplete's aqDateTime into the object. 




  var date = aqDateTime.SetDateElements(year, month, day);
  var date2 = aqDateTime.AddDays(date, 2);
  var date2Str = aqConvert.DateTimeToStr(date2);
  var noww = new Date(date2Str);



If I return the 'noww' variable (a Javascript Date object) to the keyword test, the keyword test will allow me to save the 'noww' value in a object variable. However! If I return date2 (a TestCompete Date object) to the keyword test, the keywod test will NOT allow me to save the returned 'date2' value to a keyword test's object variable. It is so unusual because it is their own object. I liked using the aqDateTime object because it was easy to manipulate the dates with it, but I'll use the old fashion Javascript Date object from now on. Thanks everyone!

Both answers helped to get me pointed in a good direction. I guess I'll accept the one with code example in it.

date2 is the TestComplete aqDateTime object, noww is the Javascript date object



Occasional Contributor

Here is some code if anyone ever wants to know how to convert aqDateTime to javascript Date



function AddDaysToToday(daysToAdd)
  // Test Complete Date Object
  var date = aqDateTime.Now();
  date = aqDateTime.AddDays(date, daysToAdd);
  year = aqDateTime.GetYear(date);
  month = aqDateTime.GetMonth(date);
  day = aqDateTime.GetDay(date);
  // Javascript Date Object
  var jsDate = new Date(`${year}-${month}-${day}`);

  return jsDate;


Here are some other useful methods ... useful code snippets:

function GetMonth_FromDate(jsDate)
  // Month number starts at 0 for some reason
  var month = jsDate.getMonth() + 1;
  return month;

function GetDay_FromDate(jsDate)
  var day = jsDate.getDate();
  return day;

function GetYear_FromDate(jsDate) 
  var month = jsDate.getYear;
  return jsDate.getFullYear();

function AddDaysToJavascriptDate(jsDate, numOfDaysToAdd)
  var dateModified = new Date(date); 
  dateModified.setDate(date.getDate() + numOfDaysToAdd);

  return dateModified;


Showing results for 
Search instead for 
Did you mean: