Cat Posted September 11 Share Posted September 11 I am trying to put a date range with a separating dash, but if the end date is not present, I need the the separating dash to disappear. so if there are both dates (example): 10/13-10/14 if there is no ending date (example): 10/13 I've been able to do a hidden dash with times, but I cannot figure out how to do the hidden dash trick with a date and keep all the date options. I converted the Date format to JavaScript which is the following code: // 01_enddate1format - ID82 - v01 - cat // Rule converted from XML Template "Format Date": // Begin XML Template selections // var dateField = "enddate1"; // "Choose the date field:" (Required): FieldOrRuleList var format = "M/d"; // "Choose the format:" (Required): PickList ["M/d" (3/14), "M/d/yy" (3/14/01), "M/d/yyyy" (3/14/2001), "MM/dd/yy" (03/14/01), "MM/dd/yyyy" (03/14/2001), "d/M" (14/3), "d/M/yy" (14/3/01), "d/M/yyyy" (14/3/2001), "dd/MM/yy" (14/03/01), "dd/MM/yyyy" (14/03/2001), "d/NNN/yyyy" (7/Mar/2001), "dd/NNN/yyyy" (07/Mar/2001), "d/MMM/yyyy" (7/March/2001), "dd/MMM/yyyy" (07/March/2001), "MMM d, yyyy" (March 14, 2001)] var useDashes = false; // "Use dashes (-) instead of slashes (/)": CheckBox var includeWeekday = false; // "Prepend weekday name": CheckBox var language = "English"; // "Language (for day and month names)": Language // End XML Template selections // if (dateField != "enddate1") var theDate = ""; else var theDate = DateFromString(RuleOrField(dateField)); if (useDashes) { format = ReplaceSubstring(format, "/", "-"); } if (includeWeekday) { var delim = ""; if (format.indexOf(',') > -1) delim = ','; format = " - "+ "EE" + delim + " " + format; } return '-' + FormatDate(theDate, format, language); Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted September 11 Share Posted September 11 I would make a separate function, or a separate rule, to format each date. Then make another rule to combine them, like so: return [Rule("01_startdate1format"), Rule("01_enddate1format")].join('-'); Quote Link to comment Share on other sites More sharing options...
Cat Posted September 11 Author Share Posted September 11 And the winner is: if (Filed("enddate1") == '') return Rule("01_startdate1format") else return [Rule("01_startdate1format"), Rule("01_enddate1format")].join('-'); Thank you Mr Korn! Quote Link to comment Share on other sites More sharing options...
Dan Korn Posted September 11 Share Posted September 11 2 hours ago, Cat said: And the winner is: if (Filed("enddate1") == '') return Rule("01_startdate1format") else return [Rule("01_startdate1format"), Rule("01_enddate1format")].join('-'); Thank you Mr Korn! That could be accomplished in a single statement, like so: return [Rule("01_startdate1format"), Rule("01_enddate1format")].filter(String).join('-'); 1 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.