GlideDate converstion

erniec
Giga Expert

Good morning everyone,

I cannot for the life of me figure out how to convert a string date of dd-MMM-yy(01-Jan-16) to a GlideDate standard format of yyyy-mm-dd 2016-01-16.   For whatever reason, having the month in the simpledate string throws the conversion off.   Anyone have any suggestions because I am wreaking my brain over here . I have read all of the wikis and may I have missed something so I apologize in advance if this has already been addressed.

Thanks in advance

Ernie

1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Ernest,



You should be able to do this with GlideDate(). I tried this in a background script and it worked.



var gdt = new GlideDate();


gdt.setValueUTC("01-Jan-16", "dd-MMM-yy");


gs.print(gdt.getValue());



GlideDateTime - ServiceNow Wiki


View solution in original post

4 REPLIES 4

epam
Kilo Guru

Hi Ernest,



following script (server side)   works fine on my instance (Fuji version):



var tt = '10-Feb-12';


var nt = new GlideDateTime();


nt.setDisplayValue(tt, 'dd-MMM-yy');


gs.print("time is:" + nt.getDisplayValue());



output is: time is:2012-02-10 00:00:00



Hope I have understood your issue correct...


Hey epam



Thanks for your response,



I am simply testing this in a scheduled job and outputting the result to the log and I get an error that 10-Feb-12 is an unparseable date.


Brad Tilton
ServiceNow Employee
ServiceNow Employee

Hi Ernest,



You should be able to do this with GlideDate(). I tried this in a background script and it worked.



var gdt = new GlideDate();


gdt.setValueUTC("01-Jan-16", "dd-MMM-yy");


gs.print(gdt.getValue());



GlideDateTime - ServiceNow Wiki


This is exactly what I was looking for. Thank you so much Brad. Dates is one thing I would like to outsource