Jump to content

If the Date value is present, I need a dash, if not, the dash and date need to not show, help?


Cat

Recommended Posts

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);

 

 

Link to comment
Share on other sites

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('-');

 

  • Thanks 1
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...