- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2023 06:54 AM
Hello All,
i need to get the current month name(ex January) , current year (ex 2023) and no of days in the current month(ex 31) from current date.
Iam using below script
var gdt2 = new GlideDateTime();
var gdt = gdt2.getValue();
var month = gdt.getMonthUTC();
var year = gdt.getYearUTC();
var days = gdt.getDaysInMonthUTC();
Here iam not getting the values for month year and no of days.
when i print i should get like month = January
year = 2023
days = 31
Thanks&Regards,
Avinash
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2023 12:09 PM
Since you are only interested in date (not time) details, there is no need to use GlideDateTime, GlideDate suffices. But GlideDateTime will also work. Running code
var gd = new GlideDate();
var dateInfo = {
year: gd.getYearLocalTime(),
month: getTranslatedMonthName(gd.getMonthLocalTime()),
daysRemainingInMonth: gd.getDaysInMonthLocalTime() - gd.getDayOfMonthLocalTime(),
};
gs.debug(JSON.stringify(dateInfo, null, '\t'));
function getTranslatedMonthName (monthIndex) {
return monthIndex > 0 && monthIndex < 13 ?
gs.getMessage(new global.GregorianCalendarGenerator().MONTHS[monthIndex - 1]) :
monthIndex;
}
in Scripts - Background results in output:
*** Script: [DEBUG] {
"year": 2023,
"month": "January",
"daysRemainingInMonth": 19
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-13-2023 09:04 AM - edited ‎01-13-2023 10:35 AM
You're welcome!
As for the problem,
daysRemainingInMonth: gd.getDaysInMonthLocalTime() - gd.getDayOfMonthLocalTime(),
needs to be "simplified" to:
daysRemainingInMonth: gd.getDaysInMonthLocalTime(),
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-12-2023 12:09 PM
Since you are only interested in date (not time) details, there is no need to use GlideDateTime, GlideDate suffices. But GlideDateTime will also work. Running code
var gd = new GlideDate();
var dateInfo = {
year: gd.getYearLocalTime(),
month: getTranslatedMonthName(gd.getMonthLocalTime()),
daysRemainingInMonth: gd.getDaysInMonthLocalTime() - gd.getDayOfMonthLocalTime(),
};
gs.debug(JSON.stringify(dateInfo, null, '\t'));
function getTranslatedMonthName (monthIndex) {
return monthIndex > 0 && monthIndex < 13 ?
gs.getMessage(new global.GregorianCalendarGenerator().MONTHS[monthIndex - 1]) :
monthIndex;
}
in Scripts - Background results in output:
*** Script: [DEBUG] {
"year": 2023,
"month": "January",
"daysRemainingInMonth": 19
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-13-2023 08:54 AM
Hi,
Thank you very much for the response.
These are working but for the last one i need number of days in a current month not days remaining.
Regards,
Avinash
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-13-2023 09:04 AM - edited ‎01-13-2023 10:35 AM
You're welcome!
As for the problem,
daysRemainingInMonth: gd.getDaysInMonthLocalTime() - gd.getDayOfMonthLocalTime(),
needs to be "simplified" to:
daysRemainingInMonth: gd.getDaysInMonthLocalTime(),