Forum Discussion

DainiusA's avatar
DainiusA
Contributor
3 years ago

(aqDateTime["Today"](), "%Y%m%d") -1); problem

TesComplete 14.01 version:   Code: var DateYesterday = (aqConvert["DateTimeToFormatStr"](aqDateTime["Today"](), "%Y%m%d") -1); Log["Message"]("Date inputed: " + (aqConvert["DateTimeToFormatStr"](...
  • npaisley's avatar
    npaisley
    3 years ago

    Hey DainiusA!

     

    Good news here is that aqDateTime also has a AddDays function that will allow you to add or remove a specific amount of days that will adhere to the calendar. 

     

    For instance, in the code below we create variables that hold Todays date, then we subtract one from it. The AddDays function will roll the time back to the previous month if Todays date is the first of the month.

     

    // script start

    function yesterDay()

     

        var today, yesterdayRaw, yesterdayFormatted;

     

        today = aqDateTime.Today();
        yesterdayRaw = aqDateTime.AddDays(today, -1);
        yesterdayFormatted = aqConvert.DateTimeToFormatStr(yesterdayRaw, "%Y%m%d");

        Log["Message"]("yesterdayFormatted " + (yesterdayFormatted));

    // script end

     

     

    Here are some docs that cover these functions. I hope this helps!

    https://support.smartbear.com/testcomplete/docs/scripting/working-with/dates/javascript.html

    https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqdatetime/adddays.html