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
Linda Hope 27Linda Hope 27 

Calculate retirement date by subtracting retirement age from birthdate

How can i calculate retirement date (Retirement_Date__c) by subtracting birthdate (birthdate) from retirement age (Retirement_Age__c).  I would like to breakout the birth date by years and months to make the retirement date more accurate.

I tried to write the formula and was getting an error
KrishnaAvvaKrishnaAvva
Hi Linda,

Make sure that the 2 fields are same datatype - date.
Then simply use the subtract methor Date1-Date2.

More Data formulas to play around : https://help.salesforce.com/articleView?id=formula_examples_dates.htm&type=5

Regards,
Krishna Avva
chakri makamchakri makam
nice
Linda Hope 27Linda Hope 27
Hi Krishna.  Thank you for the reply.  I should have been more clear.  I am having trouble getting the birthdate to break out into years and months.  I can't figure out the code for that part.
KrishnaAvvaKrishnaAvva
Hi Linda,

Month(Date) and Year(Date) will give you the respective values.
 
Ajay K DubediAjay K Dubedi
Hi Linda,

Simple code Follow this step you get the difference between two dates:

 
public class diffirenceTimeDate {
    public static void subtractdate(){
        Try{
            DateTime firstdate=DateTime.newInstance(05,02,2016, 07,08,55);
            DateTime seconddate=DateTime.newInstance(02,01,2016, 06,07,55);
            integer subyear=firstdate.year()-seconddate.year();
            system.debug('Diffirence year='+subyear);
            integer submounth=firstdate.month()-seconddate.month();
            system.debug('Diffirence mounth='+submounth);
            integer subday=firstdate.day()-seconddate.day();
            system.debug('Diffirence day='+subday);
            integer subhour=firstdate.hour()-seconddate.hour();
            system.debug('Diffirence Hour='+subhour);
            integer submint=firstdate.minute()-seconddate.minute();
            system.debug('Diffirence Minute='+submint);
            integer submili=firstdate.millisecond()-seconddate.millisecond();
            system.debug('Diffirence Millisecond='+submili);
        }
        Catch(Exception e)
        {
            System.debug('Error in reason:' +e.getCause() + 'Line number:' +e.getLineNumber());
        }
    }
}

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com



 
Linda Hope 27Linda Hope 27
Thank you! I will hopefully get a chance to try it today. If not, then Monday. I will certainly let you know how it works. LINDA HOPE Administrative Associate Lee Sipe & Associates, Inc./8GL T 301.216.1111 // F 301.216.1160 15245 Shady Grove Rd., Suite 240, Rockville, MD 20850 Investment advisory services offered through Raymond James Financial Services Advisors, Inc. Lee Sipe & Associates, Inc. is not a registered broker/dealer and is independent of Raymond James Financial Services.