Formula Field javascript for Dates

Posted by intekra on 19-Jun-2016 10:55

Hi,

Can someone please guide me how to do formula fields for a date calculations..

1) date field + 30 days = 

ex) 6/1/2016 + 30 = 7/1/2016

2) date field 1 - date field 2

ex) 6/1/2016 - 8/1/2016 = 60

Thanks

Jeff

All Replies

Posted by murali on 19-Jun-2016 11:16

The first step is to get the field value and make a JS date out of it.
Then you should be able to do JS Date API to do all calculations.
 
 

Posted by intekra on 20-Jun-2016 10:31

Thank for the info, however keep in mind I am not a programmer and this is foreign to me.

Can you provide me quick example...? My field on my object is {!Invoice_Date}.

I created a formula field called due date, and I need to add 30 days to this date to show in the new Due Date field.

Thanks

Jeff

Posted by Paulh0763 on 21-Jun-2016 08:11

Try this it should work for you to return a date with 30 Days added...

var dueDate  = new Date('{!Invoice_Date}');

dueDate .setDate(dueDate.getDate() + 30);

return dueDate;

Paul

Posted by intekra on 23-Jun-2016 13:17

Thanks Paul

This thread is closed