I need to add a date in the future by x days in the format dd/mm/yyyy, the first step is to have a way to reliably get a date in the future.
eg. today is 18/3/2015 I'd like to have variable FollowUpDate be 4 days later on 22/3/2015
Consequently I am trying to add this function to Selenium IDE:
Date.prototype.addDays = function(days)
{
var dat = new Date(this.valueOf());
dat.setDate(dat.getDate() + days);
return dat;
}
var dat = new Date();
alert(dat.addDays(5))
Reference: Add days to JavaScript Date
I have tried the following, with no luck, (using guidance from here: How to create custom functions in Selenium IDE? ) thanks for any suggestions out there...
<tr>
<td>storeEval</td>
<td>new Date();</td>
<td>today</td>
</tr>
<tr>
<td>storeEval</td>
<td>(Date.prototype.addDays = function(days) { var dat = new Date(this.valueOf()); dat.setDate(dat.getDate() + days); return dat; })var dat = storedVars['today'];dat.addDays(5)</td>
<td>FollowUpDate</td>
</tr>
This results in an error: [error] Threw an exception: missing ; before statement
Other ideas:
- contemplating adding the function to the user-extension.js
- wondering if I should use another function? eg Set date 10 days in the future and format to dd/mm/yyyy (e.g. 21/08/2010)