Hi,

I have a custom content for 'persons' (not users) which includes a date field for the person's date of birth. I would like to create a block which lists today's birthdays (or this week's birthdays) using views (to start, the block would just show a list with the node title of the matching nodes).

What would be the easiest way to do that? Basically I need to filter this field and see if its month/day equals today's month/day. It seems that date+cck+views alone cannot accomplish this.

Many thanks.

V.

Comments

VM’s picture

date = now

if the date = now you have the control you need for "todays birthdays"

if you use date > now, you will have "upcoming birthdays"

if you use date < now, you will have a "past birthdays"

vitormp’s picture

Thanks,

My problem is that the field "field_dob" contains the date of birth as yyyy/mm/dd.

I don't see a way to strip the year to make the comparison between 'now' and the value in 'field_dob' in the views editor.

vitormp’s picture

Thanks. I will take a look at the "computed field" module.

daniels____’s picture

Hello. I know that I write in this post one year later, but I want to contribute with my code.

I have set a CCK date field, to user input the birthday.

I have set a Computed CCK Field, to display days to the next birthday with the next code:

// asigno el valor del campo CCK a una variable:
$dob = $node->field_birthday[0]['value'];

//extraigo el año, el mes y el día, del campo CCK y lo convierto a tipo númerico.
$b_year = (int) substr($dob,0,4);
$b_month = (int) substr($dob,5,2);
$b_day = (int) substr($dob,8,2);

//guardo el valor númerico del día, més y año actual:
$now_day = (int) date('j');
$now_month = (int) date('n');
$now_year = (int) date('Y');

/*
Si el el més del cumpleaños es el actual y el cumpleaños aún no ha pasado
hacemos una simple resta.
*/
if (($now_month == $b_month) && ($now_day <= $b_month)) { 
    $nb = $b_day - $now_day;
}
/*
Si el més del cumpleaños, es mayor que el actual:
sumamos:
+ los días que le quedan al mes
+ los días de los meses entre medio
+ los días desde el inicio del mes del cumpleaños hasta el cumpleaños
*/
elseif ($b_month > $now_month) {
    $nb = cal_days_in_month(CAL_GREGORIAN, $now_month, $now_year) - $now_day;
    for ($i = $now_month + 1; $i < $b_month; $i++) { // sumo los días de los meses de entre medio
      $nb += cal_days_in_month(CAL_GREGORIAN, $i, $now_year);
    }
    $nb += $b_day;
}
/*
En caso contrario, el cumpleaños es el año que viene:
sumamos:
+ los días que quedan de mes
+ los días de los meses hasta diciembre
+ los días desde enero hasta el mes anterior al cumpleaños
+ los días desde el inicio del mes del cumpleaños hasta el cumpleaños
*/
else {
    $nb = cal_days_in_month(CAL_GREGORIAN, $now_month, $now_year) - $now_day;
    for ($i = $now_month+1; $i <= 12; $i++) {
      $nb += cal_days_in_month(CAL_GREGORIAN, $i, $now_year);
    }
    for ($i = 1; $i < $b_month; $i++) {
      $nb += cal_days_in_month(CAL_GREGORIAN, $i, $now_year + 1);
    }
    $nb += $b_day;
}

$node_field[0]['value'] = $nb;

Sorry for my english n.n

PD: I have to implement an exception. For example, my uncle has born on February 29 :)