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.

getByFormat is not working as expected!?

Ravi Chandra_K
Kilo Patron
Kilo Patron

find_real_file.png

the expected output is 2005-01-31 but I'm getting 0036-06-27. how to resolve this?

 

find_real_file.png

1 ACCEPTED SOLUTION

Muhammad Khan
Mega Sage

Hi Kukunooru,

 

Use the following in background script;

var gd = new GlideDateTime();
gd.setValue('31-03-2005');
gs.print(gd.getDate());
*** Script: 2005-03-31

Hopefully, this will resolve your query.

View solution in original post

20 REPLIES 20

Jaspal Singh
Mega Patron
Mega Patron

Can you try below

var gd = new GlideDate(); 
gd.setValue('2021-04-21');
gs.info(gd.getByFormat("yyyy-MM-dd"));

Mohith Devatte
Tera Sage
Tera Sage

HELLO @Kukunooru Ravi Chandra ,

PLEASE TRY THIS SCRIPT 

var gd = new GlideDate();

gs.setValue('31-01-2005');
gs.print(gd.getByFormat('yyyy/MM/dd'));

PLEASE MARK MY ANSWER CORRECT IF IT HELPS YOU

tried exact thing but I'm getting output as 2022/08/02

Hello @Kukunooru Ravi Chandra ,

sorry my bad there is a typo in my script .

ALSO IF YOU WANT TO DO IT BASED ON FIELDS YOU can try this

var sd = g_form.getValue("estimated_start_date_field_name");


var ed = g_form.getValue("estimated_end_date_field_name");


var startDate = new GlideDate(sd);


var endDate = new GlideDate(ed);


var dif = gs.dateDiff(startDate, endDate, false);

alert(dif)

Please mark my answer correct if it helps you

Mark this answer correct if it helps you