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

Is there an easy way to convert a string date to a Glide Date

tbisca
Tera Contributor

Hello,

I'm working on an integration where they are passing me the date as a string. The contains the following - 'March 11 2016'. I want to be able to set that to a glide date. I've tried a number of different things.

For Example

var gDate = new GlideDate();

gDate.setValue('March 11 2016');

Causes unparseable date error.

I know javascript has a date that allows you to pass a string, but how would I make that a glide date.

var d = new Date("October 13 2014");

Any insight would be greatly appreciated.

Tim Bisca

1 REPLY 1

venkatiyer1
Giga Guru

Hi Tim,



There are a few ways to achieve the solution. One way to achieve this would be:



var dd =   Date.parse('March 11 2016'); // gives the milliseconds value




// if this code is in server side use the below lines, above line is common to both server side and client side below


var gDate = new GlideDateTime();


gDate.setValue(parseInt(dd, 10));


gs.print(gDate);


//gDate is the glide date time




// If the code is in client side



var ga = new GlideAjax('DateTimeUtils');


ga.addParam('sysparm_name','msToGlideDateTime');


ga.addParam('sysparm_value', dd);


ga.getXMLWait();


var newGDT = ga.getAnswer();


//newGDT is the glidedatetime