Set last day of month in date field

lucky24
Tera Contributor

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?

 

2 REPLIES 2

Kainat Latif1
Tera Contributor

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.

 

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.