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
AnnieEAnnieE 

Date in DOB field based on age

I found a formula that returns an age expressed in years, months and days when a date is entered in the DOB field. Now I need a DOB entered based on the age field (again expressed as years, months, days.) 

This is for animals where we can be supplied with either an approximate DOB or an approximate age. We need which ever of these two fields is blank to auto-populate based on it's complementary field. 

Thank you.
Arun Kumar 1141Arun Kumar 1141

Hi,
Try the below formula, It will calculate the DOB(expressed as years, months, days.) Based on the entered age
DATE( YEAR(TODAY()) - FLOOR(Age_Field__c / 12), MOD(MONTH(TODAY()) - MOD(Age_Field__c, 12), 12), DAY(TODAY()) )

Mark it as betst answer if this helps. 
Thanks
Arun

SubratSubrat (Salesforce Developers) 
Hello Annie,

You can also try with the below formula :
 
IF(ISBLANK(DOB_c), TODAY() - DATE(YEAR(TODAY()) - FLOOR(Agec), MONTH(TODAY()), DAY(TODAY())), DOB_c)

Hope this helps !
Thank you.​​​​​​​
John JangJohn Jang
I was also stuck at that point and thank you so much for asking this question and I would say thaks to all of you who helps to get a point. I have cleared my point with the help of you guys.
Thanks again
AnnieEAnnieE
Thanks for this response. This formula definitely works!😀👍 However, I am stumped on how best to use the two formulas I have (Age and DOB calculations) so that each returns a read/write field. I've tried to set up both as formula fields which produces a read-only result in the complementary field. I need both fields to be read/write so that the user can enter whichever value they have available (Age or DOB) and it will auto-populate the complementary field. Would it be best to use these formulas in a flow to get the desired result?
Andrew Gillan 30Andrew Gillan 30
Flows would be a yes.

The question is then which way to do it.
Options:
  • Create a button that invokes a flow that you use to populate the fields - consider making the fields read only on the layout.
  • Fast update flow triggered on save which populated whichever field is not filled. You may need to decide which field has precedence.
  • Embed a screen flow as a component.
It depends on the business preference, user base, and whether you want it locked down, but I would look at them in order of the above as options.
Where I say fields need precedence above, if both the DOB and the AGE are entered, does the DOB win over the AGE and then AGE is recalculated.  And if using the fast update flow, I would also do a test for the fields being changed so the flow does not always run.

Regards
Andrew