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

@Kukunooru Ravi Chandra try this i have update the script

Lovely1
Tera Contributor

Hi @Kukunooru Ravi Chandra 

If you want date in 'yyyy-mm-dd' Use simple this, It will show output as yyyy-mm-dd

var gd = new GlideDate();
gs.info(gd);
 
find_real_file.png

this is returning current date in expected format. I have set some date to gd in dd-mm-yyyy format then it is giving incorrect date

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

the setValue() function in GlideDate always expects date in the internal format i.e. yyyy-MM-dd

So it won't work in the manner you are writing.

Already the value you are trying to get is in that format yyyy-MM-dd then what is your requirement?

regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur!

if I can't set dd-MM-YYYY by setValue(), is there anyway I can convert the dd-MM-YYYY to YYYY-MM-dd.

my actual requirement is to caluculate the duration. but the substract method is not working because of the format. I have tried multiple community solutions but no use. so I wanted to convert the dates to YYYY-mm-dd in client script so that I can get the duration.

find_real_file.png