- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2020 11:33 AM
Building a billing application with a scheduled job that will build a CSV file. The issue is the call gs.endOfThisMonth(); returns the value in GMT and for our instance it is 6 or 7 am on the 1st depending on Daylight Savings time. Is there an easy way to use this function to return the local end of the month or should a different way be used.
gs.endOfThisMonth(); returns 2020-02-01 06:59:59 a any day in January.
Thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2020 11:52 AM
Hi David,
Please refer to below link:
Thanks,
Sumanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2020 11:52 AM
Hi David,
Please refer to below link:
Thanks,
Sumanth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2020 07:18 AM
Using setDayOfMonthUTC() was the easiest way. I just did gd = gd.setDayOfMonthUTC(31); and it always returns the last day of the month.
I was never able to get gs.endOfThisMonth(); to actually return the last day of the month. The only way this would work for this project is if you did:
gd.endOfThisMonth();
gd.addDaysLocalTime(-1); This would work because the current project does not care about the time.
There needs to be a new call gd.endOfThisMonthLocalTime();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2020 11:58 AM
I am a little puzzled about the use of gs.endOfThisMonth(); when your speaking of scheduled aswell?
But you could a "combo" of the below.
So first find the number of days in month
var gdt = new GlideDateTime();
gs.info(gdt.getDaysInMonthUTC());
Then find the last day
var gdt = new GlideDateTime();
gdt.setDayOfMonthLocalTime(whatevernumberofdate);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-29-2020 12:05 PM
You could use this to calculate (and set) the last working day of the month, in "local time"
function isLastWorkingDay(gdt) {
var today = gdt.getDayOfWeekLocalTime();
var thisMonth = gdt.getMonthLocalTime();
switch (today) {
// Saturday and Sunday are NOT the last working day of the month
case 6:
case 7:
return false;
break;
// If it's a Friday, add 3 and see if the month changes.
case 5:
var nextMonday = gdt;
nextMonday.addDaysLocalTime(3);
var nextMondayMonth = nextMonday.getMonthLocalTime();
return (nextMondayMonth != thisMonth);
break;
// If it's a Mon-Thu add one and see if the month changes
default:
var nextDay = gdt;
nextDay.addDaysLocalTime(1);
var nextDayMonth = nextDay.getMonthLocalTime();
return (nextDayMonth != thisMonth);
break;
}
}
var now = new GlideDateTime();
var lwd = isLastWorkingDay(now);
gs.info('Last working day=' + lwd);