Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to convert array value into getbyformat

Elakkiya A
Tera Contributor

I have tried the below code and it's not working with the array. Showing as undefined

var gValue = rel.begin.getDisplayValue();
var dateTime = gValue.split(' ');
    var date = dateTime[0];
    var niceTime = date.getByFormat('EEEE dd MMMM YYYY');
6 REPLIES 6

Tai Vu
Kilo Patron
Kilo Patron

Hi @Elakkiya A 

getByFormat is a method from the GlideDate class. Your can refer to below

getByFormat(String format)

 

So the issue is that your date variable was not initiated as the GlideDate object.

Assume the dateTime[0] have a corrected date value, you can try this modification.

var date = new GlideDate(dateTime[0]);

 

Cheers,

Tai Vu

Elakkiya A
Tera Contributor

Hi @Maik Skoddow and @Tai Vu ,

 

I am trying the get the below field value which date and time, I need only the date from that and need to change the format to Tuesday 23 January 2024.

Screenshot 2024-01-23 090548.png

But the issue is when I give as getDate instead of getDisplayValue it's showing the previous date as 22 Jan.

Is there any other way I can convert this?