I need some help with a way to convert a date stored as a string to a date field in the same object.
We had to do this as we imported a lot of excel data and the column that holds dates, also held text.
I was hoping I could use a rule and a copy value action along with a field processor.
However I can’t get the field processor to work, I tried all of the existing field processors.
Here is an extract of the data, as you can see some columns have text and I want to skip those and copy the date from “Award Date – string” to “Award Date (NEW) – date”
I setup the field processor to take a string an input and a date/datetime as output, but when I return a date from field processor I get an error.
Any help would be appreciated.
Thanks
JonathanFS
So I figured out the Field Processor Output needs to be a date string.
/**
* Field Processor: toLocaleDateString
* Processes individual date string column and converts toLocaleDateString
*/
var debug = true;
// convert date string into date
var dt = new Date(params.input);
debug ? cs.log(`dt: ${dt}`) : null;
// Check is valid
if (isNaN(dt)) {
debug ? console.log(`Invalid date: ${input}`) : null;
return null;
}
// format date as string
let formattedDate = dt.toLocaleDateString('en-UK', {
day: '2-digit',
month: '2-digit',
year: 'numeric'
});
debug ? cs.log(`formattedDate: ${formattedDate}`) : null;
return formattedDate;
This now works as expected, converting the dates and erroring on non dates.
I will add some error handling now I’ve got it working.