How to use addMonth method in scoped application?

Sathwik1
Tera Expert

Hi All,

I know how to add months in scoped applications(I hope below code works for it), but need some more info...

There is a "Date" field on the table... when I run the code, then it needs to update the date as "Next month first date"

Ex: Suppose if date is 18-04-2022(It will be dynamic), after the code runs it needs to update as 01-01-2022

var datee = new GlideDate();
datee.addMonthsUTC(1);
gs.info(datee);

1 ACCEPTED SOLUTION

Hi,

check this link

How to find the first day of Month

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

addMonthsUTC is on GlideDateTime and not GlideDate

var datee = new GlideDateTime();
datee.addMonthsUTC(1);
gs.info(datee);

Regars
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

if date is 18-04-2022 then next month's first date is 1st May 2022

You can add 1 month to your date; then determine the first day of that month; anyhow it would be 1st

So once you know the current month i.e. April; you can get 1st May

Regars
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

I tried the below code @Ankur Bawiskar but not getting expected output.

var datee = new GlideDateTime();
datee.addMonthsUTC(1);
var date = datee.beginningOfThisMonth(datee);
gs.info(date);

Hi,

check this link

How to find the first day of Month

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader