Upland OL User community

Issue with parsing a string containing "th" as a date


I’m new to using the DataMapper and PlanetPress. I’m attempting to extract data from a .csv file and I’ve run into an issue when attempting to extract a date. I hope someone can help.

In the .csv file, the dates are written as “5th May 2022”. I believe the “th” is my problem.

I’ve set the following properties for this field:
Type = Date
Date/Time format: Custom
Pattern: ddth MM yyyy

Unfortunately, Connect isn’t able to parse the data using these settings. Anyone know if this is achievable?

You’ll need to make your field Based on: Javascript and use the data.extract()

Then build your script:

var dateStr = data.extract(1,22,0,1,"<br />").trim();
var day = /^\d{1,2}/g.exec(dateStr)[0];
var year = /\d{4}/g.exec(dateStr)[0];
var month = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'].indexOf(/^\d{1,2}[a-z]{2}\s([a-zA-Z]+),\s\d{4}$/gi.exec(dateStr)[1])+1;


and if you want it with 0 padding:


Thanks Hamelj, that’s working now