Conversion of date/time format

mahiakash
Tera Contributor
Hello 
I have to map the value to date/time field from transform map. In data source i am getting the value in the below format
09/29/2020 7:39 PM. I need to add 12 hours if it is PM.
 
I want to change this to mentioned format  09/29/2020 19:39:00.
 
needed help if Anyone faced this type of scenario.
 
Thanks
 
1 REPLY 1

Shoheb_IbaaBoss
Tera Guru

Hi,

Please try below:

 

  1. Navigate to Transform Maps:

    • Go to "System Import Sets" > "Transform Maps."
  2. Open the Transform Map:

    • Open the Transform Map associated with your import set.
  3. Edit the Date/Time Field Mapping:

    • Find the mapping for the date/time field that you want to transform.
    • In the "Field Map" section, locate the field you want to transform.
  4. Add a Scripted Transform:

    • If there isn't a scripted transform already, add one by clicking "New" in the "Field Map" section.
    • Choose "Script" as the transform type.
  5. Write the Script:

    • Write a script to parse the incoming date/time value, convert it to the desired format, and adjust the time if it is PM. Below is an example script:

(function transformEntry(source, map, log, target /*undefined onStart*/ ) {
var dateStr = source.u_your_date_time_field; // Replace with the actual field name

if (dateStr) {
var dateObj = new GlideDateTime();
dateObj.setDisplayValue(dateStr);

// Check if it's PM and add 12 hours
if (dateObj.isPM()) {
dateObj.addDaysUTC(0);
dateObj.addHoursUTC(12);
}

// Format the date in the desired format
target.u_your_date_time_field = dateObj.getDisplayValue();
}
})(source, map, log, target);

 

Replace "u_your_date_time_field" with the actual field name you are working with.

 

Regards,

Shoheb