Runtime error on adding working days to current date
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Runtime error on adding working days to current date
Hi Guys,
I have written a method to add working days to current date but its throwing an runtime exception while running below code
function addWorkDaysToDate(fromDate, days)
{
var count = 0;
while (count < days)
{
fromDate.setDate(fromDate.getDate() + 1); ----------------------------------------------Breaks on this line
if (fromDate.getDay() != 0 && fromDate.getDay() != 6) // Skip weekends
count++;
}
return fromDate.toDateString();
}
Value i am passing for example is fromDate: 02/02/18 and days: 4
Please assist on what is incorrect
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
is fromDate passed as a string? If so, you can't call the setDate method. You need to convert the string to a date time and then user associated methods.
For that matter, there is built in functionality in test complete for manipulating dates. Try the following.
function addWorkDaysToDate(fromDateString, days){ var fromDate = aqConvert.StrToDate(fromDateString); var count = 0; while (count < days){ fromDate = aqDateTime.AddDays(fromDate, 1); if ((aqDateTime.GetDayOfWeek(fromDate) !=1) && (aqDateTime.GetDayOfWeek(fromDate) != 7)){ count++ } } return aqConvert.DateTimetoStr(fromDate); }
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
