Convert date/time in "2024-05-22T16:00:40Z" format to date/time format in ServiceNow

Gopi22
Giga Guru

Hi Team,

 

We have a requirement to load data from a third-party source in to ServiceNow (custom table). 

One challenge is the date/time format provided by the third-party application is in "2024-05-22T16:00:40Z" format. We need to convert this and update to the date/time field in ServiceNow (Created). 

 

Please let me know any pointers that would be helpful. 

 

Thanks,

Gopi

1 ACCEPTED SOLUTION

Hi Sandeep,

 

Thank you for responding 🙂 Appreciate your effort. 

 

I have not looked in to the approach you suggested though, because I was able to move ahead with another approach which is to use the below script in my transform map field map script. This worked as required. Hope this be helpful to anyone having same or similar requirement. 

 

var sourceDatTim = source.u_created_at;
var formatdatTim = sourceDatTim.replace('T',' ').replace('Z',' ');
var targetDatTim = new GlideDateTime(formatdatTim);
return targetDatTim;

 

Thank you again 🙂 

 

Regards,

Gopi

View solution in original post

2 REPLIES 2

Community Alums
Not applicable

Hi @Gopi22 ,

This is kind of a complex one !!

so this is what i could find from stack overflow :

You need to set both .SSS and Z with your dateFormat, so your dateFormat should be yyyy-MM-dd'T'HH:mm:ss.SSSZ.

let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
let date = dateFormatter.date(from: "2017-01-09T11:00:00.000Z")
print("date: \(date)")

 

Hi Sandeep,

 

Thank you for responding 🙂 Appreciate your effort. 

 

I have not looked in to the approach you suggested though, because I was able to move ahead with another approach which is to use the below script in my transform map field map script. This worked as required. Hope this be helpful to anyone having same or similar requirement. 

 

var sourceDatTim = source.u_created_at;
var formatdatTim = sourceDatTim.replace('T',' ').replace('Z',' ');
var targetDatTim = new GlideDateTime(formatdatTim);
return targetDatTim;

 

Thank you again 🙂 

 

Regards,

Gopi