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

Nithin21
Tera Expert

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 ?

3 REPLIES 3

Akshata jamdar
Mega Guru

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

 

 

asifnoor
Kilo Patron

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.