How can I calculate the last day of the month? getDaysInMonthUTC() doesn't work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2022 06:46 AM
Hii!
I need to do the calculation that returns true 3 days before the end of the month. This was my idea:
var today = new GlideDateTime();
today = today.getDate();
var daysInMonth = new GlideDateTime();
daysInMonth.getDaysInMonthUTC();
var daysDiff = GlideDateTime.subtract(today, daysInMonth);
if (daysDiff == 3){
answer = true;
}
but it is not working, I tried with today's date and that the dateDiff == 14 inside the if and it returns me 1970-01-01 13:44:50, any ideas?
- Labels:
-
Team Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2022 12:45 AM
Thank you for marking my response as helpful.
I believe I have answered your original question on getting last day of month
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-17-2022 05:50 PM
Hi Rocio,
Following will calculate date that's 3 days from the end of this month.
var gdt = new GlideDateTime(gs.endOfThisMonth());
var gt = new GlideTime();
gt.setValue("72:00:00");
gdt.subtract(gt);
gs.info(gdt.getDisplayValue());
Execution result. The time is off by 1 second.
*** Script: 2022-03-28 23:59:59