Jump to content

Need date 90 days in future


debbiespray

Recommended Posts

Hello -

 

I need to return a date that is 90 after a given date - this is what I'm trying:

 

var myDate = (Field("BookingStartDate"));

var numDaysAhead = 90;

myDate.setDate(myDate.getDate() + numDaysAhead);

return FormatDate (myDate, "lm d, yyyy");

 

I used several other postings to arrive at this. Any idea why this doesn't validate? It doesn't like the beginning of line 3. Any help would be much appreciated!

 

Thanks,

Debbie

Link to comment
Share on other sites

Hoping to get just a little more help with this one - I need to have the 90 days out only if an end date isn't provided. When I enter the below, validating says "BookingEndDate_RULE, line 8: SyntaxError: syntax error" (which is the else if)...can you see what I'm doing wrong?

--------------------------------------

if (Field("BookingEndDate") = "");

{

var myDate = DateFromString(Field("BookingStartDate"));

var numDaysAhead = 90;

myDate.setDate(myDate.getDate() + numDaysAhead);

return FormatDate (myDate, "lm d, yyyy");

}

else if (Field("BookingEndDate") != "");

{

return FormatDate(Field ("BookingEndDate"), ("lm d, yyyy"))

}

 

--------------------------------------

Thanks so much!

Link to comment
Share on other sites

Syntax errors usually mean a character was missing or used incorrectly. In this case, you do not use semicolons at the end of the IF and ELSE lines (unless the action performed is on the same line).

 

You were also missing the 2nd equal sign in your IF statement and adding a condition to your ELSE statement is redundant (the ELSE captures any scenario that causes the IF test to be false).

 

I indicated in red what is added and commented out what is not needed:

if (Field("BookingEndDate") =[color="Red"]=[/color] "") [color="Green"]// unnecessary --> ;[/color]
{
var myDate = DateFromString(Field("BookingStartDate"));
var numDaysAhead = 90;
myDate.setDate(myDate.getDate() + numDaysAhead);
return FormatDate (myDate, "lm d, yyyy");
}
else [color="Green"]// unnecessary --> if (Field("BookingEndDate") != "");[/color]
{
return FormatDate(Field ("BookingEndDate"), ("lm d, yyyy"))
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...