Drupal Tutorials

User age from date of birth – the CCK way!

In this tutorial, submitted by Ms_Kristina, we will be using CCK to determine age from a birthday using date, and computed field. This would work well with node-profile (5.x), and content profile (6.x). I am personally using content profile along with the 6.x version of Drupal.

First off you need the modules listed below:
Computed Field – http://drupal.org/project/computed_field
Date Field – http://drupal.org/project/date
CCKhttp://drupal.org/project/cck

I am assuming you know how to install CCK, and that it is installed at this point.

1. Date module installation

Download the tar ball from the link I provided above.

Extract tar ball into the modules folder for your drupal install & upload to your server.

Go to Administer > Site Building > Modules

You will see a list of modules, a new group of modules called “Date/Time” will be available to select.

Date installation

Select “Date”, “Date API”, and “Date Timezone” — then scroll down and save configuration.

Go to Administer and you will see a list of tasks – look for “Date & Time” which you will find under the Site configuration heading.

Date configuration

Select your default timezone, select whether or not you want user-configurable timezones, and what day you want to be the first day of the week –- then scroll down and save configuration.

2. Creating birthday/date of birth field

Go to Administer, under the heading “Content Management” select “Content Types”.

Choose the content type you’re adding the field to and click “Manage Fields” – in my case it was to the Profile node type.

Scroll down and you will see an area to add a new field.

Date field

Enter in the information below:

Label: Birthday
Field: dob
Select Field Type: Date
Widget: Select List
Hit save.

On the next screen enter the following information:

Default Value: select what you want.
Default Value from to Date: select what you want.
Custom Input Format: ‘F j, Y’
Years back and forward: -100:+10
Time increment: 1
Customize Date Parts: Blank
Required: Checked off
Number of values: 1
To Date: Never
Granularity: Year, Month, and Day
Default Display: Medium
Time zone handling: Site’s time zone
Hit Save.

Your birthday field has been created!

3. Installing the Computed Field module

Download the tar ball from the link I provided above.

Extract tar ball into the modules folder for your drupal install & upload to your server.

Go to Administer > Site Building > Modules

You will see a list of modules, a group of modules called “CCK” will be available.

Select “Computed Field” — then scroll down and save configuration.

4. Creating an age field

Go to Administer, under the heading “Content Management” select “Content Types”.

Choose the content type you’re adding the field to and click “Manage Fields” – in my case it was to the Profile node type.

Scroll down and you will see an area to add a new field.

Enter in the information below:

Label: Age
Field: age
Type of Data to Store: Computed
Form element to edit the data: Computed
Hit save.
Computed field

On the next screen enter the following:

Label: Age
Widget Type: Computed
Help text: Blank
Default Value PHP Code: Blank
Required: not checked off
Number of values: 1

Computed Code:

<?php
if (!$node->nid) node_save($node);
$dob = $node->field_bday<sup class="footnote"><a href="#fn1121637270586f17fe7c8fe">0</a></sup>['value'];
$now = time();
$then = strtotime($dob);
$diff = date('Y', $now) – date('Y', $then);

if(
$diff < 0) /* ideally you want to prevent this from happening */
echo '??? – negative age.';

if((
$diff > 0) && (date('z',$now) < date('z',$then)))
$diff —;
$node_field<sup class="footnote"><a href="#fn1121637270586f17fe7c8fe">0</a></sup>['value'] = $diff;
?>

Display this field: checked off.
Display Format:

<?php
$display
= $node_field_item['value'];
?>

Store using database settings below: checked off
Data type: int
Data length: 3
Default value: blank
Not NULL: checked off
Sortable: checked off

Hit Save.

Your age field has been created!

If you edit your birthday on a given node, and then view it the age should come up accurately. You may also want to go to your Content Profile node type “Display Fields” and alter how the fields are displayed.

It’s only a quick tutorial but it should help you get up and running quickly.

Commenting on this Tutorial is closed.

Categories:

Comments (44)

deepthi's picture

followed the steps,but the wrong age is displayed.what ever dob i give the field displays th age as 39.am i going wrong anyhwere.
Thanks

deepthi's picture

my mistake,the field name was wrong..its working now.
we can display zodiac based on dob.woking on it now
thanks

it is also working for me. thanks for the great information.
orlando porcelain veneers

Freelance's picture

I have code for getting the astrological sign based on the birthdate for a computed field. :)

Remove

<?php
and
?>
as they are not necessary — they just format the code on the site.

Astrological Sign Code:

<?php
if (!$node->nid) node_save($node);

$dob = $node->field_bday<a href="#fn1121637270586f17fe7c8fe">0</a>['value'];

$dob_y = substr($dob,0,4);
$dob_year = (int) $dob_y;
$dob_m = substr($dob,5,2);
$dob_monthss = (int) $dob_m;
$dob_d = substr($dob,7,2);
$dob_day = (int) $dob_y;

switch (
$dob_monthss)
{
    case
1:
        if (
$dob_day >= 19)
        {
             
$node_field<a href="#fn1121637270586f17fe7c8fe">0</a>['value'] = "Capricorn";
        }
        else
        {
             
$node_field<a href="#fn1121637270586f17fe7c8fe">0</a>['value'] = "Aquarius";
        }
        break;

   case
2:
        if (
$dob_day >= 18)
        {
           
$node_field<a href="#fn1121637270586f17fe7c8fe">0</a>['value'] = "Aquarius";
        }
        else
        {
           
$node_field<a href="#fn1121637270586f17fe7c8fe">0</a>['value'] = "Piscies";
        }
        break;

    case
3:
        if (
$dob_day >= 20)
        {
           
$node_field<a href="#fn1121637270586f17fe7c8fe">0</a>['value'] = "Piscies";
        }
        else
        {
           
$node_field<a href="#fn1121637270586f17fe7c8fe">0</a>['value'] = "Aries";
        }
        break;
       
    case
4:
        if (
$dob_day >= 19)
        {
             
$node_field<a href="#fn1121637270586f17fe7c8fe">0</a>['value'] = "Aries";
        }
        else
        {
           
$node_field<a href="#fn1121637270586f17fe7c8fe">0</a>['value'] = "Taurus";
        }
        break;

    case
5:
        if (
$dob_day >= 20)
        {
           
$node_field<a href="#fn1121637270586f17fe7c8fe">0</a>['value'] = "Taurus";
        }
        else
        {
           
$node_field<a href="#fn1121637270586f17fe7c8fe">0</a>['value'] = "Gemini";
        }
        break;

    case
6:
        if (
$dob_day >= 20)
        {
              
$node_field<a href="#fn1121637270586f17fe7c8fe">0</a>['value'] = "Gemini";
        }
        else
        {
           
$node_field<a href="#fn1121637270586f17fe7c8fe">0</a>['value'] = "Cancer";
        }
        break;

    case
7:
        if (
$dob_day >= 22)
        {
           
$node_field<a href="#fn1121637270586f17fe7c8fe">0</a>['value'] = "Cancer";
        }
        else
        {
           
$node_field<a href="#fn1121637270586f17fe7c8fe">0</a>['value'] = "Leo";
        }
        break;

    case
8:
        if (
$dob_day >= 22)
        {
           
$node_field<a href="#fn1121637270586f17fe7c8fe">0</a>['value'] = "Leo";
        }
        else
        {
              
$node_field<a href="#fn1121637270586f17fe7c8fe">0</a>['value'] = "Virgo";
        }
        break;

    case
9:
        if (
$dob_day >= 22)
        {
           
$node_field<a href="#fn1121637270586f17fe7c8fe">0</a>['value'] = "Virgo";
        }
        else
        {
           
$node_field<a href="#fn1121637270586f17fe7c8fe">0</a>['value'] = "Libra";
        }
        break;

    case
10:
        if (
$dob_day >= 22)
        {
           
$node_field<a href="#fn1121637270586f17fe7c8fe">0</a>['value'] = "Libra";
        }
        else
        {
           
$node_field<a href="#fn1121637270586f17fe7c8fe">0</a>['value'] = "Scorpio";
        }
        break;

    case
11:
        if (
$dob_day >= 21)
        {
           
$node_field<a href="#fn1121637270586f17fe7c8fe">0</a>['value'] = "Scorpio";
        }
        else
        {
           
$node_field<a href="#fn1121637270586f17fe7c8fe">0</a>['value'] = "Sagittarius";
        }
        break;

    case
12:
        if (
$dob_day >= 21)
        {
           
$node_field<a href="#fn1121637270586f17fe7c8fe">0</a>['value'] = "Sagittarius";
        }
        else
        {
           
$node_field<a href="#fn1121637270586f17fe7c8fe">0</a>['value'] = "Capricorn";
        }
        break;
       
    default:
       
$node_field<a href="#fn1121637270586f17fe7c8fe">0</a>['value'] = "Error";
        break;
}
?>

Chinese Zodiac Code:

<?php
if (!$node->nid) node_save($node);

$dob = $node->field_bday<a href="#fn1121637270586f17fe7c8fe">0</a>['value'];

$dob_y = substr($dob,0,4);
$year = (int) $dob_y;
$dob_m = substr($dob,5,2);
$month = (int) $dob_m;
$dob_d = substr($dob,7,2);
$day = (int) $dob_y;

$cdate_monthdata = array(
0=>array(8,0,0,0,0,0,0,0,0,0,0,0,29,30,7,1),
1=>array(0,29,30,29,29,30,29,30,29,30,30,30,29,0,8,2),
2=>array(0,30,29,30,29,29,30,29,30,29,30,30,30,0,9,3),
3=>array(5,29,30,29,30,29,29,30,29,29,30,30,29,30,10,4),
4=>array(0,30,30,29,30,29,29,30,29,29,30,30,29,0,1,5),
5=>array(0,30,30,29,30,30,29,29,30,29,30,29,30,0,2,6),
6=>array(4,29,30,30,29,30,29,30,29,30,29,30,29,30,3,7),
7=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,4,8),
8=>array(0,30,29,29,30,30,29,30,29,30,30,29,30,0,5,9),
9=>array(2,29,30,29,29,30,29,30,29,30,30,30,29,30,6,10),
10=>array(0,29,30,29,29,30,29,30,29,30,30,30,29,0,7,11),
11=>array(6,30,29,30,29,29,30,29,29,30,30,29,30,30,8,12),
12=>array(0,30,29,30,29,29,30,29,29,30,30,29,30,0,9,1),
13=>array(0,30,30,29,30,29,29,30,29,29,30,29,30,0,10,2),
14=>array(5,30,30,29,30,29,30,29,30,29,30,29,29,30,1,3),
15=>array(0,30,29,30,30,29,30,29,30,29,30,29,30,0,2,4),
16=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,3,5),
17=>array(2,30,29,29,30,29,30,30,29,30,30,29,30,29,4,6),
18=>array(0,30,29,29,30,29,30,29,30,30,29,30,30,0,5,7),
19=>array(7,29,30,29,29,30,29,29,30,30,29,30,30,30,6,8),
20=>array(0,29,30,29,29,30,29,29,30,30,29,30,30,0,7,9),
21=>array(0,30,29,30,29,29,30,29,29,30,29,30,30,0,8,10),
22=>array(5,30,29,30,30,29,29,30,29,29,30,29,30,30,9,11),
23=>array(0,29,30,30,29,30,29,30,29,29,30,29,30,0,10,12),
24=>array(0,29,30,30,29,30,30,29,30,29,30,29,29,0,1,1),
25=>array(4,30,29,30,29,30,30,29,30,30,29,30,29,30,2,2),
26=>array(0,29,29,30,29,30,29,30,30,29,30,30,29,0,3,3),
27=>array(0,30,29,29,30,29,30,29,30,29,30,30,30,0,4,4),
28=>array(2,29,30,29,29,30,29,29,30,29,30,30,30,30,5,5),
29=>array(0,29,30,29,29,30,29,29,30,29,30,30,30,0,6,6),
30=>array(6,29,30,30,29,29,30,29,29,30,29,30,30,29,7,7),
31=>array(0,30,30,29,30,29,30,29,29,30,29,30,29,0,8,8),
32=>array(0,30,30,30,29,30,29,30,29,29,30,29,30,0,9,9),
33=>array(5,29,30,30,29,30,30,29,30,29,30,29,29,30,10,10),
34=>array(0,29,30,29,30,30,29,30,29,30,30,29,30,0,1,11),
35=>array(0,29,29,30,29,30,29,30,30,29,30,30,29,0,2,12),
36=>array(3,30,29,29,30,29,29,30,30,29,30,30,30,29,3,1),
37=>array(0,30,29,29,30,29,29,30,29,30,30,30,29,0,4,2),
38=>array(7,30,30,29,29,30,29,29,30,29,30,30,29,30,5,3),
39=>array(0,30,30,29,29,30,29,29,30,29,30,29,30,0,6,4),
40=>array(0,30,30,29,30,29,30,29,29,30,29,30,29,0,7,5),
41=>array(6,30,30,29,30,30,29,30,29,29,30,29,30,29,8,6),
42=>array(0,30,29,30,30,29,30,29,30,29,30,29,30,0,9,7),
43=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,10,8),
44=>array(4,30,29,30,29,30,29,30,29,30,30,29,30,30,1,9),
45=>array(0,29,29,30,29,29,30,29,30,30,30,29,30,0,2,10),
46=>array(0,30,29,29,30,29,29,30,29,30,30,29,30,0,3,11),
47=>array(2,30,30,29,29,30,29,29,30,29,30,29,30,30,4,12),
48=>array(0,30,29,30,29,30,29,29,30,29,30,29,30,0,5,1),
49=>array(7,30,29,30,30,29,30,29,29,30,29,30,29,30,6,2),
50=>array(0,29,30,30,29,30,30,29,29,30,29,30,29,0,7,3),
51=>array(0,30,29,30,30,29,30,29,30,29,30,29,30,0,8,4),
52=>array(5,29,30,29,30,29,30,29,30,30,29,30,29,30,9,5),
53=>array(0,29,30,29,29,30,30,29,30,30,29,30,29,0,10,6),
54=>array(0,30,29,30,29,29,30,29,30,30,29,30,30,0,1,7),
55=>array(3,29,30,29,30,29,29,30,29,30,29,30,30,30,2,8),
56=>array(0,29,30,29,30,29,29,30,29,30,29,30,30,0,3,9),
57=>array(8,30,29,30,29,30,29,29,30,29,30,29,30,29,4,10),
58=>array(0,30,30,30,29,30,29,29,30,29,30,29,30,0,5,11),
59=>array(0,29,30,30,29,30,29,30,29,30,29,30,29,0,6,12),
60=>array(6,30,29,30,29,30,30,29,30,29,30,29,30,29,7,1),
61=>array(0,30,29,30,29,30,29,30,30,29,30,29,30,0,8,2),
62=>array(0,29,30,29,29,30,29,30,30,29,30,30,29,0,9,3),
63=>array(4,30,29,30,29,29,30,29,30,29,30,30,30,29,10,4),
64=>array(0,30,29,30,29,29,30,29,30,29,30,30,30,0,1,5),
65=>array(0,29,30,29,30,29,29,30,29,29,30,30,29,0,2,6),
66=>array(3,30,30,30,29,30,29,29,30,29,29,30,30,29,3,7),
67=>array(0,30,30,29,30,30,29,29,30,29,30,29,30,0,4,8),
68=>array(7,29,30,29,30,30,29,30,29,30,29,30,29,30,5,9),
69=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,6,10),
70=>array(0,30,29,29,30,29,30,30,29,30,30,29,30,0,7,11),
71=>array(5,29,30,29,29,30,29,30,29,30,30,30,29,30,8,12),
72=>array(0,29,30,29,29,30,29,30,29,30,30,29,30,0,9,1),
73=>array(0,30,29,30,29,29,30,29,29,30,30,29,30,0,10,2),
74=>array(4,30,30,29,30,29,29,30,29,29,30,30,29,30,1,3),
75=>array(0,30,30,29,30,29,29,30,29,29,30,29,30,0,2,4),
76=>array(8,30,30,29,30,29,30,29,30,29,29,30,29,30,3,5),
77=>array(0,30,29,30,30,29,30,29,30,29,30,29,29,0,4,6),
78=>array(0,30,29,30,30,29,30,30,29,30,29,30,29,0,5,7),
79=>array(6,30,29,29,30,29,30,30,29,30,30,29,30,29,6,8),
80=>array(0,30,29,29,30,29,30,29,30,30,29,30,30,0,7,9),
81=>array(0,29,30,29,29,30,29,29,30,30,29,30,30,0,8,10),
82=>array(4,30,29,30,29,29,30,29,29,30,29,30,30,30,9,11),
83=>array(0,30,29,30,29,29,30,29,29,30,29,30,30,0,10,12),
84=>array(10,30,29,30,30,29,29,30,29,29,30,29,30,30,1,1),
85=>array(0,29,30,30,29,30,29,30,29,29,30,29,30,0,2,2),
86=>array(0,29,30,30,29,30,30,29,30,29,30,29,29,0,3,3),
87=>array(6,30,29,30,29,30,30,29,30,30,29,30,29,29,4,4),
88=>array(0,30,29,30,29,30,29,30,30,29,30,30,29,0,5,5),
89=>array(0,30,29,29,30,29,29,30,30,29,30,30,30,0,6,6),
90=>array(5,29,30,29,29,30,29,29,30,29,30,30,30,30,7,7),
91=>array(0,29,30,29,29,30,29,29,30,29,30,30,30,0,8,8),
92=>array(0,29,30,30,29,29,30,29,29,30,29,30,30,0,9,9),
93=>array(3,29,30,30,29,30,29,30,29,29,30,29,30,29,10,10),
94=>array(0,30,30,30,29,30,29,30,29,29,30,29,30,0,1,11),
95=>array(8,29,30,30,29,30,29,30,30,29,29,30,29,30,2,12),
96=>array(0,29,30,29,30,30,29,30,29,30,30,29,29,0,3,1),
97=>array(0,30,29,30,29,30,29,30,30,29,30,30,29,0,4,2),
98=>array(5,30,29,29,30,29,29,30,30,29,30,30,29,30,5,3),
99=>array(0,30,29,29,30,29,29,30,29,30,30,30,29,0,6,4),
100=>array(0,30,30,29,29,30,29,29,30,29,30,30,29,0,7,5),
101=>array(4,30,30,29,30,29,30,29,29,30,29,30,29,30,8,6),
102=>array(0,30,30,29,30,29,30,29,29,30,29,30,29,0,9,7),
103=>array(0,30,30,29,30,30,29,30,29,29,30,29,30,0,10,8),
104=>array(2,29,30,29,30,30,29,30,29,30,29,30,29,30,1,9),
105=>array(0,29,30,29,30,29,30,30,29,30,29,30,29,0,2,10),
106=>array(7,30,29,30,29,30,29,30,29,30,30,29,30,30,3,11),
107=>array(0,29,29,30,29,29,30,29,30,30,30,29,30,0,4,12),
108=>array(0,30,29,29,30,29,29,30,29,30,30,29,30,0,5,1),
109=>array(5,30,30,29,29,30,29,29,30,29,30,29,30,30,6,2),
110=>array(0,30,29,30,29,30,29,29,30,29,30,29,30,0,7,3),
111=>array(0,30,29,30,30,29,30,29,29,30,29,30,29,0,8,4),
112=>array(4,30,29,30,30,29,30,29,30,29,30,29,30,29,9,5),
113=>array(0,30,29,30,29,30,30,29,30,29,30,29,30,0,10,6),
114=>array(9,29,30,29,30,29,30,29,30,30,29,30,29,30,1,7),
115=>array(0,29,30,29,29,30,29,30,30,30,29,30,29,0,2,8),
116=>array(0,30,29,30,29,29,30,29,30,30,29,30,30,0,3,9),
117=>array(6,29,30,29,30,29,29,30,29,30,29,30,30,30,4,10),
118=>array(0,29,30,29,30,29,29,30,29,30,29,30,30,0,5,11),
119=>array(0,30,29,30,29,30,29,29,30,29,29,30,30,0,6,12),
120=>array(4,29,30,30,30,29,30,29,29,30,29,30,29,30,7,1)
);
        
$cdate_zodiacarray = array("null","Rat","Ox","Tiger","Rabbit","Dragon","Snake","Horse","Sheep","Monkey","Rooster","Dog","Pig");

$cdate_total = 11;
$cdate_cntotal = 0;

for (
$y=1901; $y<$year; $y++)
{
   
$cdate_total+=365;
    if (
$y%4==0) $cdate_total ++;
}

switch (
$month)
{
    case
12:
       
$cdate_total+=30;
        break;
       
    case
11:
       
$cdate_total+=31;
        break;
       
    case
10:
       
$cdate_total+=30;
        break;
       
    case
9:
        
$cdate_total+=31;
         break;
        
    case
8:
        
$cdate_total+=31;
         break;
        
    case
7:
        
$cdate_total+=30;
         break;
        
    case
6:
        
$cdate_total+=31;
         break;
        
    case
5:
        
$cdate_total+=30;
         break;
        
    case
4:
        
$cdate_total+=31;
         break;
        
    case
3:
        
$cdate_total+=28;
         break;
        
    case
2:
        
$cdate_total+=31;
         break;


if (
$year%4==0 and $month>2)
{
    
$cdate_total++;
}

$cdate_total = $cdate_total+($day-1);

$myeardiff = $year-1900;

for (
$x=0;$x<=$myeardiff;$x++)
{
    for (
$y=1;$y<=13;$y++)
    {
        if (
$cdate_cntotal<$cdate_total)
        {
           
$cdate_cntotal+=$cdate_monthdata[$x][$y];
           
$cdate_cnyear = $x;
           
$cdate_cnmonth = $y;
        }
    }
}

$cdate_zodiacnumber = $cdate_monthdata[$cdate_cnyear][15];

$node_field<a href="#fn1121637270586f17fe7c8fe">0</a>['value'] = $cdate_zodiacarray[$cdate_zodiacnumber];
?>

Thanks for the code.
It looks preety neat.
Here’s a correction to your switch case loop

case 1:
        if ($dob_day <= 19)
        {
              $node_field0['value'] = "Capricorn";
        }
        else
        {
              $node_field0['value'] = "Aquarius";
        }
        break;

$dob_day should be (<=) 19 to make it Capricorn
I have noticed this mistake go till the end of the loop
Here’s an alternative code
if (!$node->nid) node_save($node);

$dob = $node->field_dob0['value'];

$dob_y = substr($dob,0,4);
$dob_year = (int) $dob_y;
$dob_m = substr($dob,5,2);
$dob_monthss = (int) $dob_m;
$dob_d = substr($dob,8,2);
$dob_day = (int) $dob_d;

if(($dob_monthss==1 && $dob_day>20)||($dob_monthss==2 && $dob_day<20)){
          $node_field0['value'] = "Aquarius";
     }else if(($dob_monthss==2 && $dob_day>18 )||($dob_monthss==3 && $dob_day<21)){
         $node_field0['value'] =  "Pisces";
     }else if(($dob_monthss==3 && $dob_day>20)||($dob_monthss==4 && $dob_day<21)){
          $node_field0['value'] =  "Aries";
     }else if(($dob_monthss==4 && $dob_day>20)||($dob_monthss==5 && $dob_day<22)){
          $node_field0['value'] =  "Taurus";
     }else if(($dob_monthss==5 && $dob_day>21)||($dob_monthss==6 && $dob_day<22)){
          $node_field0['value'] =  "Gemini";
     }else if(($dob_monthss==6 && $dob_day>21)||($dob_monthss==7 && $dob_day<24)){
          $node_field0['value'] =  "Cancer";
     }else if(($dob_monthss==7 && $dob_day>23)||($dob_monthss==8 && $dob_day<24)){
          $node_field0['value'] =  "Leo";
     }else if(($dob_monthss==8 && $dob_day>23)||($dob_monthss==9 && $dob_day<24)){
          $node_field0['value'] =  "Virgo";
     }else if(($dob_monthss==9 && $dob_day>23)||($dob_monthss==10 && $dob_day<24)){
          $node_field0['value'] =  "Libra";
     }else if(($dob_monthss==10 && $dob_day>23)||($dob_monthss==11 && $dob_day<23)){
          $node_field0['value'] =  "Scorpio";
     }else if(($dob_monthss==11 && $dob_day>22)||($dob_monthss==12 && $dob_day<23)){
          $node_field0['value'] =  "Sagittarius";
     }else if(($dob_monthss==12 && $dob_day>22)||($dob_monthss==1 && $dob_day<21)){
          $node_field0['value'] =  "Capricorn";
     }

Notice I changed $dob_d = substr($dob,7,2); to $dob_d = substr($dob,8,2); coz sometimes you may pickup the dashes like in my case instead of 19 php was picking out -1.

You can also add images instead of the text. Heres how
$node_field0['value'] =  "<img src='You Image Location' />"

Ms_Kristina: Excellent!
But how can I translate these astrological names? In my country it sounds a little bit strange.
I tried to use drupal’s translate system but with no luck :(

VenturaCottage.com's picture

simply take the english words from above use google translate to change to your language and then paste back into the code. Example below english to Russian
http://translate.google.com/translate_t?hl=en#en|ru|Scorpio

yes kristina is doing very good service here.
regards,
penny stock list

hmm..bug? I filled out my “was born” field as 17 april.The script calculated “Aries”.It is true.But when I changed date of born to 25 of april,the astrological sign was not changed.

By Inspiration's picture

I had the same problem, there’s an error in the example above:

Change

<?php
$dob_day
= (int) $dob_y;
?>

To

<?php
$dob_day
= (int) $dob_d;
?>

Pure Solutions Internet Marketing's picture

Nice tutorial! and thanks Ms_Kristina for the astrological code!

chaosprinz's picture

When i try to submit content with this computed field i get two error-messages like this:

Parse error: syntax error, unexpected '<' in /var/www/vhosts…..httpdocs/sites/all/modules/computed_field/computed_field.module(138) : eval()'d code on line 1

and

Parse error: syntax error, unexpected '<' in /var/www/vhosts….... httpdocs/sites/all/modules/computed_field/computed_field.module(263) : eval()'d code on line 1
Has anyone an idea? My php/mysql-skills are real not the best, so i´m sorry for having to ask.

I’m getting the same error messages – any thoughts?

Thanks a million – this tutorial is great.

I figured out my problem, which was twofold:

The computed fields module apparently doesn’t like the start/end php code (i.e.

<?php
at the beginning
, and
?>
at the end. I fixed that on both the Computed Code and the Display Formats input, and error messages went away.

Also, the system computed ‘39’ as the birthday, regardless of the year input. I noticed that I had the wrong field name. So, make sure that your field name is ‘bday’, or else change it in the Computed Code.

Thanks again for this module. It is great.

Good post. I think the age never gets updated over a period of time, unless you edit the node manually. Is there any way to do it ?

Freelance's picture

I don’t know. I just know of editing the node manually.

Freelance's picture

Hrm. Mind there must be a way to make the field dynamic. I mean the birthdate doesn’t change. thinks

Maybe not saving the field result to DB would do it.

I am trying to the the same type of thing.
I have a computed field that the width of an image and returns “horizontal”, “vertical”, or “square”.I want to have an exposed filter that allows users to limit images to these parameters. (ie. if they select “vertical” they will only see play craps for free vertical images.) The issue is that the computed field filter in views is only “Is Greater Than….” and i need something like the text filters.Any suggestions?

Merge's picture

The computed field doesn’t seem to be updated when somebody had a birthday, although “store in database” is unchecked…

related issue:
http://drupal.org/node/195013

(PS: I’m new on this site, but these captcha’s are really a show-stopper for me.)

By Inspiration's picture

Works fine for me, I believe that’s what the following line is for:

<?php
if (!$node->nid) node_save($node);
?>

You also need to have store in database checked

I have run into the related issue you posted several times, I used the following methods in these circumstances:
1. create a custom module to run a node save on all related nodes on each cron run – this isn’t practical if you have a lot of nodes
2. Create a rule using the rules module to run a node save each time the related node is viewed – this works but you don’t get to see the updated node until the next time you visit the page as the action is triggered after the page loads.

Merge's picture

@vivianspencer
Maybe you’ve got all cache disabled? I’m running with normal cache settings.

And according to me, that line is only executed when creating a new node.

#2 might be an option. Would be even better if a rule could be made that also saves your profile whenever you login as user.

Realityloop Pty Ltd's picture

Here is a much shorter way to get the age from a DOB

<?php
if (!$node->nid) node_save($node);
$age = ((time() – strtotime($node->field_dob<a href="#fn1121637270586f17fe7c8fe">0</a>['value'])) / (3600 * 24 * 365));
$node_field<a href="#fn1121637270586f17fe7c8fe">0</a>['value'] = ((int) $age) ;
if (
is_null($node->field_dob<a href="#fn1121637270586f17fe7c8fe">0</a>['value'])) $node_field<a href="#fn1121637270586f17fe7c8fe">0</a>['value'] = NULL ;
?>

Insfilo's picture

thanks for this :D

Indonesia Web Design

adodis technology's picture

Hai,

Nice tutorial and thanks for using the astrological code to determine the astrological sign.

Thanks

http://www.drupal-web-developers.com

Merge's picture

By the way, these scripts above are all wrong because they don’t take leap years into account.

By Inspiration's picture

None of the scripts above are wrong, they just need improving upon. Adding the leap year shouldn’t be to hard, perhaps you could post a fix?

Merge's picture

Yes, you’re right, they aren’t wrong, just inaccurate.
I’m working on an improved script. Will post that here when it’s ready.

Great tutorial!
Is there a way I could use this info to then redirect the user to a page with additional info? Something similar to this: http://www.mylifetime.com/astrology/ruling-planets

I still can’t get this script to work. I need to use it for my make money at home website. The age will not show up.

levitra viagra cialis,cialis compared to viagra,cialis comparison viagra,cialis o viagra,
results of cialis and viagra,compare cialis viagra levitra.
viagra vs levitra vs cialis,viagra cialis comparison,
what does cialis and viagra do?,
where to buy viagra cialis sosua,
which is better viagra cialis or levitra,
‘does cialis or viagra get you harder’.
buy cialis viagra,
Buy cheap geneneric viagra online
canadian discount pharmicies viagra cialis,
cialis and viagra together,
cialis compare levitra viagra,
cialis comparison levitra viagra,
cialis dysfunction erectile levitra viagra!
cialis e viagra,
cialis levitra sales viagra.
Order discount viagra online
cialis v viagra,
cialis versus levitra versus viagra,
cialis viagra differenze,
cialis viagra levitra which is best?,
cialis with free viagra,
compare cialis viagra,
comparing cialis and viagra,
buy viagra online without prescription
difference between cialis and viagra,
difference between viagra and cialis,
differenza viagra cialis levitra,
does viagra or cialis or levitra work better for women,
dominican republic buying viagra cialis,
Buy cheap cialis online
free cialis and viagra,
generic viagra levitra cialis!
levitra viagra cialis which is best,
levitra vs cialis vs viagra,
levitra vs viagra and cialis.
Order generic cialis online

royalt's picture

Great use of Drupal in this script.
dress up

royalt's picture

I tried it again and it still works like a charm.
free games

En iyi alışveriş sitelerinden biri olan magaza.net sizlere pet shop kategorisi ile hizmet vermektedir. Bu kategoride Köpek maması , Kedi maması , Kuş yemi , Balık yemi vs birçok ürün satmaktadır. Yanı sıra kedi , köpek , kemirgen , kuş , balık , sürüngen gibi hayvanlar için bir çok ürün barındırıyor. Köpek Kategorisi içinde göze çarpan ürünler şunlardır : Köpek Bakımı ürünleri , Köpek maması , Köpek vitamini , Köpek şampuanı . Kedi Kategorisi içinde ise : Kedi Maması , Kedi Bakımı , Kedi vitamini bulundurulmaktadır. Balık Kategorisi bölmünde : Balık Yemi , Balık Akvaryumlar , Balık ilaçları . Sizlere Kısaca özetlemek istedim. Bunun yanı sıra Kuş Kategorisinde ise : Muhabbet Kuşu yemleri , Kanarya yemleri , Papağan ve Güvercin Ürünleri bulundurmaktayız. Mağazamızda uygun ve güvenilir alışverişler.

the tutorial is good.. it brought out things in a good way
Resveratrol Supplements

i got this working really well now .

duddimai's picture

Hi. Great tutorial. I have a bit of a problem with it though.

I set my birth-date for the 20th of april 1983 and it should say im 26, but it says im 27 as if we have already passed the 20th, and its only the 17th today.. did I do anything wrong?

help please? :)

the user age script is just working awesome now.. LED Emergency Lights

Yeah. as others said script works fine for me.
Buy lottery tickets online

I don’t know about what problem you has, I myself haven’t try it out yet. Maybe you can googling around? If I already know the problem, I’ll tell you. Good luck.
free samples

2. Creating birthday/date of birth field
Go to Administer, under the heading “Content Management” select “Content Types”.
Choose the content type you’re adding the field to and click “Manage Fields” – in my case it was to the Profile node type.
Scroll down and you will see an area to add a new field.
ppc advertising

that was so great!.good job!

Nice piece of information. Thanks! 8)

best penis enlargement :: penis pills :: VIGRX PLUS

This great little module is a lightweight version of the jCarousel plugin that allows you to create scrollable lists of content which can be a good way of fitting lots of content in a small area. By viewing this code I seem like lost in translation! This is not kind of thing that I know the
best, but will try to figure it out.

Most of times users are not providing correct DOB. So we can’t trust the validity of this module.
as seen on tv