Forum Discussion

ashley_cowley's avatar
ashley_cowley
New Contributor
13 years ago

Help using the aqConvert.StrToDate method

Evening all,



I am fairly new to TestComplete and I am trying to verify that the contents of a table are within a certain date range and seem to be banging my head against a brick wall a little at the moment.



I have been browsing the SmartBear support libraries and have found the aqConvert function, but does anyone know how I can store the resulting converted date as a variable to then be able to compare against another date variable (in the same boat as this one atm).



I can only find variable types of String, Int, Double, etc and no date applicable variable?



Thanks in advance for any help!

8 Replies

  • Correct me if I am wrong, but I would think it would be as simple as:







    var convertedDate = aqConvert.StrToDate(dateString);



    edit::



    Here is a much more specific example, comparing two dates, one which is converted from a string object.




     



    function fromFuture() {



    var myBirthday = "05/01/88";



     



    var convertedDate = aqConvert.StrToDate(myBirthday);



    var currentDate = aqDateTime.Today();



     



    if(aqDateTime.Compare(currentDate, convertedDate))



    {



    Log.Message("You are not from the future!");



    }



    else



    {



    Log.Message("Mission:: Protect John Connor");



    }



    }


  • Sorry, I don't think I explained what I was trying to do correctly. I am building up a suite of tests with variables that are set by returning the contents of a particular field in an on-screen grid.



    I am then trying to compare that value with some values input by process of a Test Parameter to see if the date pulled from the grid falls within the dates set by the user.



    I am building the test using the Operations part of the Workspace for the Test Steps, and the Variables that I am able to add from here are of the types I mentioned above. I am not wanting to fully code all my tests as we need the tests to be accessible to all testers, most who do not understand coding (and I only know the basics of coding too). There is an aqConvert method available in the Operations and I am able to do the convert and log the message with no problem, it is then storing that to use to compare that I am experiencing the most of my pain (and Last Operation Result will not work because I need to convert 3 StrToDate for the same compare If statement).



    Hope that makes a little more sense?

  • Hi Ashley,


     


    Maybe adding a piece of script to your project that converts the needed data will help you. To call the script from your test, you need to use the Run Script Routine operation in your test.


     

  • Hey Ashley, if I understand your question correctly you're just looking for a variable type to store the data that you've converted with the aqConvert function.



    I believe the type of varaible you are looking for is "var", which is designed to be open-ended to hold any data type. 



    So you could say:



    var convertedDate = aqConvert.StrToDate(strDate)



    and it will store the converted value as a date. 
  • Thanks all for your help, I have now managed to find a way to do what I was wanting to do using a mix of all your suggestions.



    I have written a small script and used the Run Script Routine and used a 'days between xDate and yDate' then a seperate 'days between xDate and zDate' function using the -ve and +ve returns to work out an If statement rather than an 'If xDate is between yDate and zDate then...'



    The variable var does work for what I was wanting too, thanks.



    Thanks all for your help!
  • laxsore's avatar
    laxsore
    New Contributor
    But how aqConvert.StrToDate method recognize the date format.?I mean how can I detrmine if its "mm/dd/yyyy" or  "dd/mm/yyyy"?



    I need to convert strings to dates and compare them.