Jump to content
Welcome to the new FusionPro User Forum! ×

Trim data input and format


Recommended Posts

Data comes in as this for an example:


Offer Valid 8/6/2010 to 9/19/2010


What I would like to do is capture just the DATES and format them.

I kind of have an idea on how to trim but can't figure out how to get Rule 1 below date.


Rule 1 would then return:


If the input data was 12/12/2010, then it would just return as is, no leading 0.


Rule 2 would then return:



Thanks for any insight.

Link to comment
Share on other sites

Rule 1:

var Dates = Field("OfferValid").match(/(\d+\/\d+\/\d+)/g);
return Dates && Dates[0] ? FormatDate(Dates[0], "mm/dd/yyyy") : "Invalid Date";

Rule 2:

var Dates = Field("OfferValid").match(/(\d+\/\d+\/\d+)/g);
return Dates && Dates[1] ? FormatDate(Dates[1], "mm/dd/yyyy") : "Invalid Date";

You can generalize this for any number of dates like so:

var Dates = Field("OfferValid").match(/(\d+\/\d+\/\d+)/g);
var result = "";
for (var i in Dates)
   result += FormatDate(Dates[i], "mm/dd/yyyy") + "<br>\n";
return result;

Or, you can do something this in OnRecordStart to populate multiple text variables without writing multiple rules:

var Dates = Field("OfferValid").match(/(\d+\/\d+\/\d+)/g);
for (var i in Dates)
   FusionPro.Composition.AddVariable("DateRule" + (i+1), FormatDate(Dates[i], "mm/dd/yyyy"));

Then you can use the text variables "DateRule1", "DateRule2", etc. as if you had created rules with those names.


I'll reiterate my caveat about using only numbers to represent dates, as the convention with regard to the order of the month and day is different in Europe than it is in the U.S.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...