0

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:

Community
  • 1
  • 1
Scott Spence
  • 99
  • 14

1 Answers1

1

Put a semi colon after the function:

dat.setDate(dat.getDate() + days); return dat; });
DMart
  • 2,401
  • 1
  • 14
  • 19