Forum Discussion

IAmSanjay's avatar
IAmSanjay
New Contributor
7 years ago
Solved

How to find the date differences in terms of days?

I there way to find the date differences in terms of day? ex. Date1 - Date2 = x days  
  • tristaanogre's avatar
    tristaanogre
    7 years ago

    Did you read the whole article?

     


    I quote:

    "The returned time period is measured starting from the "zero date", which is 12:00 AM, December 30, 1899. However, if the period is less than one day, then the date portion is omitted. Besides, if your locale uses the 12-hour clock notation, the resulting value is displayed using "before noon" and "after noon" abbreviations (like AM/PM in English).

    Because of these reasons, using the common aqConvert.DateTimeToStr method to display the TimeIntervalresults could yield quite odd results (like 12/31/1899 12:00:05 AM when the difference is 1 day and 5 seconds). This could be rather confusing for the values that reflect time duration. To avoid misunderstanding, it is better to use the dedicated method, TimeIntervalToStr, that returns a string in the D:HH:MM:SS format, which indicates the time passed since the "zero date"."

     

     

    So... change your code to the following:


     

    I tried this.
    var currentdate = aqDateTime.Now();
    var newDate = aqDateTime.AddDays(currentdate,3);
     
    var res = aqConvert.TimeIntervalToStr(aqDateTime.TimeInterval(currentdate, newDate));
    
    Log.Message('The interval is ' + res);

    If you specifically want to peel out the days only, use res.split(':') to return an array of the string where the first element in the array is the number of days.