new GlideDateTime().getDate(); this is giving complete date in" YYYY/MM/DD" format, I want only month and year in "MM/YYYY" this format .....what is script for this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2022 06:22 AM
new GlideDateTime().getDate(); this is giving complete date in" YYYY/MM/DD" format, I want only month and year in "MM/YYYY" this format .....what is script for this
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2022 06:35 AM
Hi animesh
Try this code to get month and year seperately.
var x= new GlideDateTime().getDate();
var year = x.getYear();
var month = x.getMonth();
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2022 06:42 AM
Yes you can also use getByFormat as suggested by monica
Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2022 06:35 AM
Hello Animesh,
Try using below code:
var a = new GlideDateTime().getDate();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2022 06:57 AM
Hi,
this should work
var gdt = new GlideDateTime();
var todayDate = new GlideDate();
todayDate.setValue(gdt.getLocalDate());
var myFormat = todayDate.getByFormat("MM/yyyy");
gs.info("My format->" + myFormat);
Output:
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader