How to get first day of the specific month.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2022 10:48 PM
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2022 11:30 PM
Hi,
Please use the script below to get which you are looking for :
var sentDateTime = new GlideDateTime("2021-11-20 12:00:00");
var daysInMonth = sentDateTime.getDaysInMonth();
var sentDay = sentDateTime.getDayOfMonth();
var firstOfMonth = new GlideDateTime(sentDateTime);
firstOfMonth.addDays( -1 * (sentDay-1));
gs.info(firstOfMonth.getDisplayValue());
This is working for me in my PDI.
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2022 11:24 PM
Hi,
You could try something like this:
var date = new GlideDateTime();
date.addMonths(-2);
gs.info('date minus two months: ' + date);
date.setDayOfMonthLocalTime(1);
gs.info('first day: ' + date);