How to get first day of the specific month.

app
Mega Expert

Hello All,

I am trying to get the first day of the specific month.

ex: someone passes (-2 from the current month), so end date  should be 2021-11-31 and start date should be 2021-11-01.
Please let me know how I can get it.

 

Thanks

6 REPLIES 6

Sulabh Garg
Mega Sage
Mega Sage

Hello

Please try below script

 

var gdt = new GlideDateTime(date);

var dt= gs.beginningOfThisMonth(gdt);

gs.print(dt);

gs.print(gdt.getDayOfWeek());

 

Also check this community link for more info https://community.servicenow.com/community?id=community_question&sys_id=69c1df6ddbdcdbc01dcaf3231f96...

 

Please Mark Correct/helpful, if applicable, Thanks!! 

Regards

Sulabh Garg

Please Mark Correct/helpful, if applicable, Thanks!!
Regards
Sulabh Garg

Hello Sulabh,

I already tried this code but it is giving me 01-01-2022.

and I want 01-11-2021.

Thanks

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

what will be the user input?

Regards
Ankur

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

Hello Ankur,

var contract_date = new GlideDateTime("2021-11-20 12:00:00");

thanks