Hello all ,
i tried a lot but unable to find and fix the problem.
i want to calculate the age of a user from his/her DOB field but how to do i dont no.
1. i created a computed field and passed the code to it also in the following way :
$birthday_date = date_make_date($node->field_dob[0]['value']);
$birthday = $birthday_date->db->parts;
//compute age
$bdayunix = mktime("", "", "", $birthday['mon'], $birthday['mday'], $birthday['year']);
$nowunix = time();
$unixage = $nowunix - $bdayunix;
$age = floor($unixage/ (365 * 24 * 60 * 60));
$node_field[0]['value'] = $age;
-----------------------------------------------------------------------------------------------------------
Data type = int
Data length = 2
Default value = 0
Required = yes
but doesn't worked for me .......only the default value is showing = 0
| Comment | File | Size | Author |
|---|---|---|---|
| Now Age_1227694846208.png | 13.28 KB | solutionpoint | |
| Now Age-1227694875167.png | 10.1 KB | solutionpoint | |
| Member Profile_1227694778457.png | 17.52 KB | solutionpoint |
Comments
Comment #1
solutionpoint commentedthe computed fields i created for age calculation is Now Age.
Please some body help out for solving this problem this is very urgent
Thanks and Regards
Kunal
Comment #2
fraguas commentedTake a look at this: http://drupal.org/node/149237
Comment #3
solutionpoint commentedi have seen this and made changes also but i am not getting the result so please let me explain clearly step by step
for which i shall remain ever thankful to you ..
thanks
kunal
Comment #4
scott859 commentedGreetings,
I was having a similar problem, but was able to fix it.
I should mention that I am using the 6.x-1.0-beta2 version.
Here is what I am using for computed code:
Here is what is in the display field:
Database:
Store using the database settings below: checked
Data type: Int
Data length: 3
Default Value: **left blank**
Not NULL: checked
Sortable: checked
Also make sure that in the above code where I'm using "field_dob" that you replace this with "field_(the name of your field that is providing the birthdate)" In this case I am usind "dob" because "field_dob" is the name of my Date field that holds the birthdate I'm using to calculate age.
When I initially created this I received a "0" as the computed age. I tried re-saving it by opening the node for edit (but not editing anything) and then hitting "save" while in edit mode and that got the correct computed age figure to display. So, for me the key was re-saving the node.
I'm fairly new to Drupal and still learning my way around so I can't say exactly why this worked at this point but maybe someone else can lend some insight into why the problem occurred initially and why the above fix worked.
Thanks,
Scott
Comment #5
mmachina commentedworks like a charm!
Comment #6
colanVersion 5 is no longer supported.