
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2017 06:18 AM
Hello,
I'd like to share the following code snipped. Since i could help myself with it it is more a information than anything else really. The following needs to be done:
Within a loop over 12 iterations aggregate the amount of records within a month and go over to the next (previous) month. In Addition to that take the Month and Year of the checked month, so it later can be displayed in a line chart. Which results in the following variables:
var monthBegin = gs.monthsAgoStart(i).toString();
var monthEnd = gs.monthsAgoEnd(i).toString();
var rawTime = new GlideDateTime(monthBegin);
// since the getMonth is f***ed up, the beginning date will always return a month later (01.01 -> Feb)
var timeToConvert = new GlideDateTime(monthEnd);
var startMonth = timeToConvert.getMonth();
var startYear = timeToConvert.getYear();
For the getMonth() method it seems as if using it with the gs.monthsAgoStart GlideDate will result in the month later. E.G.: 2017-01-01 00:00:00 somehow results in "2" as month. Even weirder: 2016-12-01 00:00:00 results in the "1" of 2017. Meaning the .getYear() is probably faulty too. For Dates later in the month this does NOT happen.
If someone knows why, please enlighten me. Other than that i can only assume, that this conversion is at fault. Btw.: using getMonthUTC()/getYearUTC() instead had the same outcome.
Greetings
Fabian
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2018 05:33 AM
Hi Fabian,
the gs time functions are a little difficult. Let me explain:
I am in timezone GMT+2 (that's in my profile).
If I run gs.monthsAgoStart(3) >> 2018-03-31 22:00:00
So today July 20 2018 minus 3 months >> that would be April 1
This means: the system's time would have been the timestamp given above when April starts in MY timezone. I know it is a little strange.
Apart from this: some gs functions are no longer available in the scoped API - like gs.monthsAgoEnd - don't ask me why. And I had my fair share of fun with the UTC functions as well.
Maybe that helps
Best,
Seb

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2018 05:33 AM
Hi Fabian,
the gs time functions are a little difficult. Let me explain:
I am in timezone GMT+2 (that's in my profile).
If I run gs.monthsAgoStart(3) >> 2018-03-31 22:00:00
So today July 20 2018 minus 3 months >> that would be April 1
This means: the system's time would have been the timestamp given above when April starts in MY timezone. I know it is a little strange.
Apart from this: some gs functions are no longer available in the scoped API - like gs.monthsAgoEnd - don't ask me why. And I had my fair share of fun with the UTC functions as well.
Maybe that helps
Best,
Seb