- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2020 04:39 AM
Hi All,
As part of integration, we will get some data monthly once into ServiceNow table.
'Usage date' is one of the field on the table [ date type field].
Our client wants to have this populated as last day of the last month.
For eg., if data arrives on June 25th, 2020,
Usage date should store it as May 31st, 2020.
could anyone help me with this requirement.
Regards,
Venkata
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2020 05:10 AM
Try this.
var month = gs.endOfLastMonth();
var monthd = new GlideDateTime(month);
monthd.addDays(-1);
gs.info(monthd);
output
Please mark this correct & helpful if it answered your question.
Thanks & Regards,
Sharjeel
Muhammad

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2020 04:45 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2020 04:50 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2020 05:27 AM
ok, may be this will help
var month = gs.endOfLastMonth();
var gdt = new GlideDateTime(month);
gdt.addDaysLocalTime(-1);
gs.info(gdt.getLocalDate());

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2020 04:52 AM
Hi VSPK
Check out setDayOfMonthUTC().
If you set it to something like 35, you'll get the last day of the month.
Also, take a look at getDayOfMonthUTC().
The day of month to change to, from 1 to 31. If this value is greater than the maximum number of days in the month, the value is set to the last day of the month.
for example.:-
var gdt = new GlideDateTime();
gdt.setDayOfMonthUTC(9);
gs.print(gdt.getDayOfMonthUTC());
Please Mark Correct and Helpful
Thanks and Regards
Gaurav Shirsat