function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AGMAGM 

Calculate the End Date from the Start Date

Does anyone have an S-Control  or Formula that will take a start date and add a duration in months to calculate an end date?

 

I've tried handling this in SF itself through a workflow rule trigger by breaking out the dates into MM DD Year fields and manipulating that way.  The problem is of course Validating the end date is a true since the current work around causes a problem.  ie: Jan 31 2007 + 1 Month = Feb 31, 2007 ... not a valid date.

 

Since we have Admin Support SF personnel tried to write a formula for the calculation and after a few weeks gave up and told me the only way to handle this is with a Custom S-Control.

 

Any suggestions / help would be appreciated.

 

Thanks

AGM

 
 
Greg HGreg H
JavaScript has a date object which will allow you to add days to a date. 
Code:
var myDate=new Date(); //declare date object
myDate.setDate(myDate.getDate()+90); //add 90 days to today's date

Without getting into too much detail what you are trying to do is possible but it will require manipulating that date object and formatting it so that you can insert your end date back into the Salesforce record.  The primary issue is that the date object in JavaScript is in a "Tue Dec 18 15:36:40 MST 2007" format and you'll need it in a "2007-12-18" format in order to insert into Salesforce.
-greg
AGMAGM

Thanks for the suggestion Greg, I'll do some experimenting.

 

In the meantime I've worked out a solution that uses a series of custom fields / formulas and workflow field updates that works like a charm when the duration is "Months" ... if anyone is in need of this functionality I would be happy top post a the work around or e-mail me.

Regards,

Andrew

 

Jay-DawgJay-Dawg

I would take your start date and use Javascript methods to extract the day, month, year from it. Then you can write a little piece of code that increments the month. Then create a new date in Javascript using the updated day, month, year. You would have to check it first yourself with a if/then or switch statement to make sure you don't create Feb 30th. I think if you pass Feb 30th to Javascript date it'll just roll it over to become Mar 2, but I'm not sure.

Here's a good source for Javascript methods:

http://www.devguru.com/Technologies/ecmascript/quickref/date.html

DalinDalin
Andrew - Can you post your solution to calculating the end date by adding months to a date. I have a formula that works as long as the result is within the same year. If the date goes beyond the end of the year it does not work. Any help would be great.

Thanks
David
GeriGeri

Hi Andrew

 

Could you post your formula.

 

I have two custom fields

Contract Start Date (Updated by workflow when opportunity changed to contract status)

Term (Picklist)

I need to calculate the Contract end date from the start date by using the term.  The term is in months.

So for example

Contract Start Date - 28/06/2010

Term 24

Contract End Date should be - 27/06/2012

 

Thanks

Geri

NijanNijan

Hi Andrew ,

 

 How r u?? hope u must b doing great @ ur end.

 

 I am in a problem.Not getting any solution to find out the End date in a Installment calculation. I need to put Start Date and Terms (In months) and through javascript Automatic the End Date Calculation will be done and printed in text box.

 

Thank you very much in advance.

 

I really barely needed it soon.Some urgency there.

 

Thank You,

 

Nijan   (rtrath@gmail.com)

GeriGeri

Hi

Not sure if this is of any help but I use a formula to calculate my contract end date, determined by start date and term in months

 

 

Contract_Start_Date__c + (365 * VALUE(Text( Term_Committed__c )) / 12)

 

Geri

NijanNijan

Really Thankful to you,

 

But not getting how to implement into javascript and to show in the text box to continue posting my form with other details.

 

Please elaborate.

 

Tnx again,

 

Nijan

Teja KokalaTeja Kokala

Hey Geri,

Your formula was helpful indeed, it works! thank you, it saved me time and effort.