converting string to GlideDateTime

steved
Kilo Explorer

Hi - hopefully someone has encountered this before and can get me over the last hurdle. I am importing records from excel into SN using a transform map. A few fields are date fields or which i have made strings - then during the transform i convert to glidedateTime. The transform reports ignored errors and the dates populate in the target but the HHMMSS do not convert but default to midnight. I need to keep as date time and in dd-mmm-yyyy hh:mm:ss format. My transform script is onBefore:

var gdt = new GlideDateTime();

gdt = source.uclosed;

target.u_closed = get + get.addDays(+1);

I have to add one day to match the source date.

Any help is appreciated.

7 REPLIES 7

The SN Nerd
Giga Sage
Giga Sage

Have you tried this



var gdt =new GlideDateTime(source.u_closed);


gdt.addDays(1);


target.u_closed = gdt;



You should be able to find the methods you need on the wiki page


GlideDateTime - ServiceNow Wiki



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Thank you Paul! I see my error in the script - this worked along with


changing the date format in the field map of the source date field. So now


the transform works without an error but still the hours minutes and


seconds default to midnight. Do you know of a wiki article that addresses


this or have an idea? I really appreciate your insight!



On Thu, Jul 16, 2015 at 8:33 PM, Paul Morris <


Your string has to be in the following format



  • value - (String) A UTC date and time using the internal format yyyy-MM-dd HH:mm:ss.


If it is in this format it should account for the HH:mm:ss if you are using the constructor below



var gdt =new GlideDateTime("2011-01-01 12:00:00");



ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022

Gurpreet07
Mega Sage

First you could create field map for those date fields and then you could specify the date format of the source fileCapture.JPGd in the field map.