Date field giving undefined value

Shwetha Nair
Giga Guru

I am trying to set the field in yyyy-mm-dd format but it is giving me undefined value.

var date = "20.10.2018";

var dt = new GlideDate(date);

var dt3 = dt.getLocalDate().getByFormat("yyyy-MM-dd");

gs.print("Date :" + dt3);

 

 

Thanks in advance!

1 ACCEPTED SOLUTION

Harish KM
Kilo Patron
Kilo Patron

Try this

var date = "20.10.2018";

var dt = new GlideDateTime(date);

var dt3 = dt.getLocalDate().getByFormat("yyyy-MM-dd");

gs.print("Date :" + dt3);

Regards
Harish

View solution in original post

5 REPLIES 5

Harish KM
Kilo Patron
Kilo Patron

Try this

var date = "20.10.2018";

var dt = new GlideDateTime(date);

var dt3 = dt.getLocalDate().getByFormat("yyyy-MM-dd");

gs.print("Date :" + dt3);

Regards
Harish

Thank you for the quick reply. It worked.

Sulabh Garg
Mega Sage
Mega Sage

Hi Shwetha,

Do it like this

var date = "20.10.2018";

var dt = new GlideDateTime(date.toString());

var dt3 = dt.getLocalDate().getByFormat("yyyy-MM-dd");

gs.info("Date :" + dt3);

 

It should work.

 

Please Mark ✅ Correct/helpful, if applicable, Thanks!! 
Regards
Sulabh Garg

 

Please Mark ✅ Correct/helpful, if applicable, Thanks!!
Regards
Sulabh Garg

Hi, 

I did try your code too. This is also correct.

Thanks for the help.