How to get last day of the last month

vspk
Giga Expert

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

1 ACCEPTED SOLUTION

MrMuhammad
Giga Sage

Try this. 

var month = gs.endOfLastMonth();
var monthd = new GlideDateTime(month);
monthd.addDays(-1);
gs.info(monthd);

 

output

find_real_file.png

Please mark this correct & helpful if it answered your question.

Thanks & Regards,
Sharjeel

 

Regards,
Muhammad

View solution in original post

5 REPLIES 5

MrMuhammad
Giga Sage

Try this. 

var month = gs.endOfLastMonth();
var monthd = new GlideDateTime(month);
monthd.addDays(-1);
gs.info(monthd);

 

output

find_real_file.png

Please mark this correct & helpful if it answered your question.

Thanks & Regards,
Sharjeel

 

Regards,
Muhammad