How to convert string field value to date field using transform map

Tribid2
Kilo Expert

How to convert string field value to date field using transform map

string field value : 01-APR-1967 (u_actual_date)-->string field

date field format : MM-dd-yyyy (actual_start)--> date field

below code not working:

OnBefore

if (!source.u_actual_date.nil()) {
var sec = Date.parse(source.u_actual_date);
var gdt = new GlideDateTime();
gdt.setNumericValue(sec);
target.actual_start = gdt.getDisplayValue();
}

 

1 ACCEPTED SOLUTION

Tribid2
Kilo Expert

I have found the solution by modifying the transform map script

On before

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {

 

var gd = new GlideDate();
gd.setDisplayValue(source.u_actual_date, "dd-MMM-yyyy");
var dt = gd.getByFormat("MM-dd-yyyy");
target.actual_date= dt;
//gs.info("SUCCESSFUL : ", dt);

 

})(source, map, log, target);

 

View solution in original post

5 REPLIES 5

Hello,

Glad you found a solution that worked for you. For any future readers, if you configure the source format correctly, you shouldn't need to build your own script to map. If your source data does not include time (such as HH:mm:ss, etc.), then in the source formatting, you wouldn't include time, just the date format as presented in your source data.

Take care!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!