Forum Discussion

torus's avatar
torus
Contributor
2 years ago

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.   ...
  • rraghvani's avatar
    2 years ago

    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
    }