Multiple Date Format

I have a date field in my data mapper (4012016, which is April 01, 2016). The month will either have 1 or two digits (4012016 or 12012016). When the month is 1 digit, I get an error message (‘unparseable date’). I have the below script but it is not quite working. Any suggestions?

data.extract(‘COLUMN39’,0).slice(4,6) + ‘/’ + data.extract(‘COLUMN39’,0).slice(6,8) + ‘/’ + data.extract(‘COLUMN39’,0).slice(0,4);

So let’s first make those data formats consistent so you can use the same formula each time. Your script should start with the following:

var myDate = ("0"+data.extract('COLUMN39',0)).substr(-8);

This pads all dates with an extra 0 at the beginning and stores the last 8 characters into a variable.

Now all you have to do is read as usual. Assuming you want the format to be MM/DD/YYYY, you’d use:

myDate.substr(0,2)+"/"+myDate.substr(2,2)+"/"+myDate.substr(4);

By the way, does this explain the other issue you were having with unparseable dates (Unparseable Date - DataMapper - Upland OL User community)? If so, I will also update that issue so other readers can benefit from the solution as well.

This works perfectly! Thank you so much for your assistance!

The other issue has been resolved, as well! There wasn’t an issue with script necessarily. The first record was a header row (no actual date in field) and was causing an error. I skipped that line in the data mapper and now all records are valid.

Thanks again.