This article has been contributed by Praful Desai a reader of Siebel Unleashed.
Requirement:
You need to calculate if a person is underage or not i.e less than 18 years of age or not. You need to return Y if they are less than 18 years (Underage) and N (Not Underage) if they are more than 18 years. It should also take care of people born in leap year.
Solution:
On the first look it typically looks like solution that can be achieved with minor scripting but Praful Desai shows us how we can use ToChar functions in side calculated fields to achieve the solution without any scripting.
- Create Calculated Field of todays date in YYYYMMDD Format:
e.g: Formatted Today Date : ToChar(Today(),’YYYY’) + ToChar(Today(),’MM’) + ToChar(Today(), ‘DD’)
Field Type: DTYPE_NUMBER - Create another Calculated Field Birth date in YYYYMMDD Format:
e.g: Formatted Birth Date : ToChar([Birth Date], ‘YYYY’) + ToChar([Birth Date], ‘MM’) + ToChar([Birth Date], ‘DD’)
Field Type: DTYPE_NUMBER - Set the Calculated Age Under 18 Flag as mentioned below:
Age Under 18 Flg : IIf(([Formatted Today Date] – [Formatted Birth Date]) < “180000″, “Y”, “N”)
Field Type: DTYPE_TEXT
This should give you an idea how to powerful calculated fields can be.