Susan Posted April 15, 2019 Share Posted April 15, 2019 I am using a rule from this site to convert 13-Oct-15 dates to October 13, 2015. It is working correctly, but when there is no data in the "GIFT_DATE" field I get this error "uncaught exception: Error in function "DateFromString": Could not convert "" to a valid date." Is there something I can add to the rule so that I don't get the error for the empty "GIFT_DATE" fields. It makes it harder to catch real errors. The rule is below: var str = Field("GIFT_DATE"); var MonthNameAbbrs = [ "jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec" ]; var month_name_part = 0; var parts = str.replace(/-/g,'/').split('/'); for (var i = 0; !month_name_part && i < parts.length; i++) { if (isNaN(parseInt(parts))) { for (var m = 0; m < MonthNameAbbrs.length; m++) { if (ToLower(parts).substr(0,3) == MonthNameAbbrs[m]) { parts = m + 1; month_name_part = i + i; break; } } } } if (month_name_part) { var mpart = month_name_part - 1; var mval = parts[mpart]; parts.splice(mpart, 1); parts.splice(0, 0, mval); } var date = DateFromString(parts.join('/')); return FormatDate(date, "lm d, yyyy"); Quote Link to comment Share on other sites More sharing options...
ScottHillock Posted April 15, 2019 Share Posted April 15, 2019 Add this as your first line: if (!Field("GIFT_DATE")){return "";} Quote Link to comment Share on other sites More sharing options...
Susan Posted April 15, 2019 Author Share Posted April 15, 2019 Thanks Scott. Just what I needed! 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.