debbiespray Posted November 1, 2012 Share Posted November 1, 2012 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 Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted November 1, 2012 Share Posted November 1, 2012 You're trying to call Date functions, but you don't have a Date object, just a String. Change the first line to: var myDate = DateFromString(Field("BookingStartDate")); Quote Link to comment Share on other sites More sharing options...
debbiespray Posted November 1, 2012 Author Share Posted November 1, 2012 This works! Thanks so much for your help. Quote Link to comment Share on other sites More sharing options...
debbiespray Posted November 2, 2012 Author Share Posted November 2, 2012 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! Quote Link to comment Share on other sites More sharing options...
esmith Posted November 3, 2012 Share Posted November 3, 2012 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")) } Quote Link to comment Share on other sites More sharing options...
debbiespray Posted November 3, 2012 Author Share Posted November 3, 2012 Thanks so much for responding - this works perfectly - really appreciate the explanations. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.