The CreatorCon Call for Content is officially open! Get started here.

How do I convert glide date to integer date

samfindlay1
Giga Expert

I want to to use a group of records from pa_scores in a Map Page script,

and I want to return values where the start_to date is last month, however

start_to is an integer date value, so how do I convert a standard glide date

into an integer date like so:

var date = new GlideDate();

date.setValue(gs.beginningOfLastMonth());

// convert here ?

gs.print(date /*as an integer date i.e 29012016*/ );

1 ACCEPTED SOLUTION

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

You should be able to do like this:



var date = new GlideDate();  


date.setValue(gs.beginningOfLastMonth());  


var dateasint = date.toString().replace('-','');


gs.print(dateasint);



and if it need to "really" be a integer you can do like this:



var date = new GlideDate();  


date.setValue(gs.beginningOfLastMonth());  


var dateasint = parseInt(date.toString().replace('-',''));


gs.print(dateasint);


View solution in original post

8 REPLIES 8

Way prettier than mine would have been.



Cookie.png


Yeah I was half-way through putting the date back together again when I saw Goran's response. Hey concatenation probably would have worked too though.


Thanks so much Goran, your method worked perfectly.



I tried this method and almost had it! I just forgot to include the "toString()" method.



And thanks everyone for coming to my aid so quickly.


warren_chan
ServiceNow Employee
ServiceNow Employee

Old thread, but this helped me achieve what I was trying to do. I did notice that the Repeat Until [repeat_until] field on the Schedule Entry [cmn_schedule_span] table was an Integer Date type, and this was the only way I was able to set it:

var schedule_span_gr = new GlideRecord('cmn_schedule_span');
if (schedule_span_gr.get(SYS ID of RECORD));
{
    var repeatUntilAsInt = date.toString().replaceAll('-', '');
    schedule_span_gr.repeat_until.setValue(repeatUntilAsInt.toString());
    schedule_span_gr.update();
}

Strangely, I couldn't set the value of the Integer Date field using an Integer, but somehow the String worked instead. There really wasn't a need to go to the Integer type at all.