How to find the date differences in terms of days?
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Check out the following.
Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I tried this.
var currentdate = aqDateTime.Now();
var newDate = aqDateTime.AddDays(currentdate,3);
var res = aqDateTime.TimeInterval(currentdate, newDate);
if I log this, I will get 1/2/1900 20:27:57
Log.Message("The interval as DateTime: " + aqConvert.DateTimeToStr(res));
What I want is the days difference which is 3 days (from Dec 30 1899 to Jan 2 1900)
How to get that 3?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 TimeInterval
results 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.
Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----
Why automate? I do automated testing because there's only so much a human being can do and remain healthy. Sleep is a requirement. So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.
Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
