Field Processors - Strings to Date/Time

Hey

I am looking to import CSV values using an import file but some values are not being pulled through.

The Date Time value is in the CSV as “dd/MMM/yy HH:mm:ss”

My Java knowledge is limited but it would be great is someone could provide an example how to process this in?

Cheers

S

the mats.delegate_to_server_function(‘string_to_editable_date’); function isn’t that clear how it is processing the input params in the String to editable date processor

Hi Simon

The String to Editable Date processor currently delegates the handling to a backend function.

The processor is pretty good at figuring out and converting string dates into a format Create can handle, but if you are still facing issues. Try the format: “yyyy-mm-dd hh:mm:ss”.

Regards
Liam

Thanks Liam

The issue in the short term is the data is from a third party and getting that change (which processes ok on other systems) may take a while.

Can I use java.time or SimpleDateFormat to process it? else I will just need to do a select case for all the months of the year to format the string for the back end

Hi Simon

I’ve quickly put something together which converts a date like “dd/MMM/yy HH:mm:ss” aka “01/Feb/20 12:13:14” to dd/mm/yy HH:SS format which is the standard date format create uses and can understand via an API / Import. (Code tested and works)

Depending on your Create version use the following.

2020

const date = new Date(params.input);
return `${date.toLocaleDateString('en-GB')} ${date.toTimeString().slice(0, 5)}`;

2021+

return {
    main: function(input, params) {
        const date = new Date(input);
        return `${date.toLocaleDateString('en-GB')} ${date.toTimeString().slice(0, 5)}`;
    }
}

Regards
Liam

Ok - much better than my attempt:

var deliverydate=params.input;
//cs.log(deliverydate);
[date,time] = deliverydate.split(" "); // splits the time and date
//cs.log("Date: "+date+" Time: "+ time);
[day,month,year] = date.split("/"); // splits the date

// Use Swtich to convert MMM value to MM
switch(month) {
	case "Jan":
	month = "01"
	break;
	case "Feb":
	month = "02"
	break;
	case "Mar":
	month = "03"
	break;
	case "Apr":
	month = "04"
	break;
	case "May":
	month = "05"
	break;
	case "Jun":
	month = "06"
	break;
	case "Jul":
	month = "07"
	break;
	case "Aug":
	month = "08"
	break;
	case "Sep":
	month = "09"
	break;
	case "Oct":
	month = "10"
	break;
	case "Nov":
	month = "11"
	break;
	case "Dec":
	month = "12"
	break;
}
//cs.log("convert Month: "+month);
// var iDate = "20"+year+"-"+month+"-"+day+" "+time; //reformats DateString to ISO
var iDate = day+"/"+month+"/"+"20"+year+" "+time; //reform to LibCreate Date input format dd/MM/yyy HH:mm
//cs.log("New DAte: "+iDate);

return iDate;                         //mats.delegate_to_server_function('string_to_editable_date');

Hi Simon,

No worries, let me know if you have any more issues with this.

Regards
Liam

Just checking - if value input is null should I handle that as this is throwing up an error (2020 version)

that worked

Added an if null return null; else … at the top

thanks for the help

S

Although it didn’t like ==null value so compared to “” empty string

Hi Simon

Try these updated snippets.

2020

if (! params.input) return

const date = new Date(params.input);
return `${date.toLocaleDateString('en-GB')} ${date.toTimeString().slice(0, 5)}`;

2021+

return {
    main: function(input, params) {
        if (! input) return

        const date = new Date(input);
        return `${date.toLocaleDateString('en-GB')} ${date.toTimeString().slice(0, 5)}`;
    }
}

Regards
Liam