Forum Discussion

tbom's avatar
tbom
Contributor
11 years ago

Calculating differences (in days) between two DateTime objects

I'm trying to calulate the difference in days, between two dates in my test script. However, it seems that aqDateTime object, doesn't allow for such calculations?



Is there someone out there that have a solution to this problem?



Eg. I have two dates 27-10-2014 and 29-10-2014, date difference should be 2, also with the following dates : 31-12-2014 and 02-01-2015.



/ Thomas



  • This seems to be the easiest way to achieve what you want:




      var Time1 = aqDateTime.Time();


      var Time2 = aqDateTime.AddTime(Time1,8,5,0,5);


      var Difference = aqDateTime.TimeInterval(Time1, Time2);


      Log.Message("The interval in Days:" + aqConvert.TimeIntervalToStr(Difference).split(":")[0]);


     

  • karkadil's avatar
    karkadil
    Valued Contributor
    This seems to be the easiest way to achieve what you want:




      var Time1 = aqDateTime.Time();


      var Time2 = aqDateTime.AddTime(Time1,8,5,0,5);


      var Difference = aqDateTime.TimeInterval(Time1, Time2);


      Log.Message("The interval in Days:" + aqConvert.TimeIntervalToStr(Difference).split(":")[0]);