Set last day of month in date field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2024 04:57 AM
Hi Team,
I have to set the last day of the month in the due date field.
For example, if I select the date "19-01-2024" then the due date field should be populated as "31-01-2024" and the date should be populated according to the user's time zone.
I have tried with some code but it always gives me 1st day of the next month.
var tz = gs.getSession().getTimeZone();
var gdt = new GlideDateTime("20/01/2024"); // current.start_date - start date is date field
gdt.setTZ(tz);
//gs.print(gdt);
gdt.addMonthsUTC(1);
gdt.setDayOfMonthUTC(1);
gdt.add(17999400);
//eom.setTimeZone('Asia/Shanghai');
gs.print(gdt);
result of the above script- 2024-02-01 04:59:59
Please can someone help me here?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2024 05:17 AM - edited ‎01-19-2024 05:20 AM
Try this:
var tz = gs.getSession().getTimeZone();
var gdt = new GlideDateTime("20/04/2024"); // current.start_date - start date is date field
gdt.setTZ(tz);
gdt.setDayOfMonthUTC(32);
gs.print(gdt);
setDayOfMonthUTC(Number day)
If the value of day is greater than the maximum number of days in the month, the value is set to the last day of the month.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2024 06:58 AM
Hi Kainat,
Thanks for your response.
I tried with above approach but I am working on the scoped application and getSession.getTimeZone and setTZ are not working in the scope application.
How can I try solve my above query.