Change glide date format to dd/mm/yyyy

JJG
Kilo Guru

Hello,

I am trying to change a new glide date format to dd/mm/yyyy before changing it to a string. So far my code is not working, what am I missing?

var gdt = new GlideDate();
gdt.getByFormat("dd-MM-yyyy");
var startOfPeriod = gdt.toString();

 

1 ACCEPTED SOLUTION

Mark Roethof
Tera Patron
Tera Patron

Hi there,

This works for me:

var gdt = new GlideDate();
gs.info(gdt.getByFormat('dd-MM-YYYY'));

Outputs: 22-03-2020

This also works:

var gdt = new GlideDate();
var startOfPeriod = gdt.getByFormat('dd-MM-YYYY').toString();

gs.info(startOfPeriod);

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

1 REPLY 1

Mark Roethof
Tera Patron
Tera Patron

Hi there,

This works for me:

var gdt = new GlideDate();
gs.info(gdt.getByFormat('dd-MM-YYYY'));

Outputs: 22-03-2020

This also works:

var gdt = new GlideDate();
var startOfPeriod = gdt.getByFormat('dd-MM-YYYY').toString();

gs.info(startOfPeriod);

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn