I have read some threads about this already but I don’t understand the code, so i’ll ask a question that works specifically with the data I already have. My database has a user’s date of birth in the following format:
yyyy-mm-dd
This field is pulled from the database using a php service, then populating a datagrid. I’m using an ItemRenderer to customise the columns. I would like to take my DOB which is accessed by {data.dob} and then work out the age in years. Do I have to split my result into days/months/years first, then calculate? or can I just do it from the DOB I get back? Also I’ve seen examples that use the date 01/01/1970 but I don’t understand how that works.
Any correct answer is greatly appreciated.
You should be able to use date Arithmetic. Just subtract the current date from the
data.dob. I would use this DateUtils class.Here is a sample. Just use choose DateDiff, then choose the birth date as your first date and today’s date as the second date. Get the answer in years, and you’ll have the person’s age.