Get the beginning of the month and last day of the month

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2020 04:10 AM
In Contract module, I would like to get the contract amount based on the selected date.
Lets say
Contract Start Date = 20th Jan 2020
Contract End Date = 20th Jan 2021
Monthly contract amount = $200
Yearly contract amount = $2400
To get a view of the contract amount for the month of Jan 2020, I would like to get the month end date (30th Jan 2020) in this case
# of Days = 30th Jan 2020 minus 20th Jan 2020
= 10 days
Contract amount (for the month of Jan ) = $200 / 10 = $20
Which Date API will be useful to make the above calculation ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2020 04:22 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2020 04:27 AM
Hi Nithin,
You can use the function "var datediff=dateDiff(String, String, boolean)" ,to calculate difference between two dates and after that you can use this variable to calculate contract amount and set it to appropriate field on form. this method will give you output in seconds you need to convert it into days.
for example:
var diffSeconds = gs.dateDiff(date1.getDisplayValue(), date2.getDisplayValue(), true);
var datediff = parseInt(diffSeconds)*60*24;
Hope this will help you.
Please mark the answer correct and helpful if it will help you to find the answer.
Regards,
Akshata

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-20-2020 04:47 AM
Hi,
Try like this.
var contract_date = new GlideDateTime("2020-01-20 12:00:00");
var end_date = contract_date.getYear()+"-"+contract_date.getMonth()+"-"+contract_date.getDaysInMonth()+" "+"12:00:00";
var gdt=new GlideDateTime(end_date);
gs.print("Last date of the month is "+gdt);
Mark the comment as a correct answer and also helpful if it helps.