Forum Discussion

mazhar555's avatar
mazhar555
Contributor
14 years ago

Date Functions

Hi,



I am looking for a routine which can return Date Interval in Number and if i add a number into a date it will return me a Date. Same as we do in excel. Can anyone help me?



Regards,

9 Replies

  • Hello Alex,



    Today happened something interesting with the aqDateTime object.

    When I run this code:



    Log.Message(aqDateTime.Today());

    Log.message(aqDateTime.AddMonths(aqDateTime.Today(), +1));



    I get this log message:

    Type   Message     Time      Link

              10/4/2010   1:49:48   

              11/1/2010   1:49:48   




    Today's date is fine, but what about today + 1 month ? Shouldn't it return 11/4/2010 ?

    This only happens in TC 7.52. TC 8 seems OK.



    Thanks,

    Andrei
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Andrei,



    I am not employed by AutomatedQA as it is stated in my signature, so I will leave the answer to their Support. :)

    But I can confirm that I got the same problem with your code using VBScript with TC7.52.



    Possible workaround:

    Log.Message(aqDateTime.SetDateElements(aqDateTime.GetYear(aqDateTime.Today()), aqDateTime.GetMonth(aqDateTime.Today()) + 1, aqDateTime.GetDay(aqDateTime.Today())));
  • Hi Alex,



    Thanks for the reply and the workaround.

    This is very interesting, especially that on Friday this wasn't an issue.



    I'm curious of the response from Automated QA. :)



    Thanks,

    Andrei
  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Andrei,



    > [...]on Friday this wasn't an issue.

    Most probably, AddMonths() rounds the result to the first day of the month (i.e. just adds the requested number of months without considering the actual number of days). Thus on Friday this wasn't an issue as Friday was Oct the 1st.
  • Hi Alex,



    I don't think this is the way AddMonths() work. I had it in my scripts for quite some time now, and until today, it worked as expected, meaning today + 1 months returns 10/4/2010 (with different formatting maybe).



  • Hello Andrei,





    Thank you for informing us about this issue. The problem has been fixed in TestComplete 8.

    For version 7, please use the workaround suggested by Alexei. As version 8 is out, no maintenance updates are planned for version 7, sorry.
  • swapnildaphal's avatar
    swapnildaphal
    Occasional Contributor
    Like Datediff  function in VB script

    Is there any method in Jscript/C# Script/any of the Testcomplete utility



    I want to calculate difference in terms of days by passing two dates in any standard format

    I am using testcomplete 6.5 enterprise edition.





    one workaround is



    var t= aqConvert["TimeIntervalToStr"](aqDateTime["TimeInterval"]("21.01.2009", "23.01.2009"))




    ~Swapnil

  • Hello,





    Among the scripting languages supported by TestComplete, only VBScript provides the DateDiff function, because it's a VBScript built-in function. So, I recommend that you continue using the TimeInterval method to calculate the difference between dates.