1

I'm having trouble with views and could use some help. I have a content type called 'person' which has a birthday date field. I'm trying to create a view for displaying all the birthdays occurring on the current day e.g. a born on this day view.

So if the person's birthday is 3rd July 1975, the person node would be displayed in the 'born on this day' view whenever it's the 3rd July - regardless of which year it is.

I've tried adding a date filter in views, with the granularity set to day and relative to 'today' but it always matches on the year rather than just the month and day.

Any idea how I could achieve this with views?

1 Answer 1

1

For drupal 7 you need only views module for do that.

  1. Add date field "field_birthday"(for example) in the user entity.
  2. Add views of type "user"
  3. Add contextual filter "user id" with checkbox "Allow multiple values"
  4. Place this code to the "PHP contextual filter code":
$results = db_query("SELECT entity_id FROM field_data_field_birthday 
    WHERE DATE_FORMAT(field_birthday_value,'%m-%d') = DATE_FORMAT(NOW(),'%m-%d') 
    AND entity_type = 'user'");
$ids = array();
foreach ($results as $result) {
    $ids[] = $result->entity_id;
}
return implode(',',$ids);

From https://www.drupal.org/node/313498#comment-7860111

In your case you might have to do a join on the node and the birthday field are return the nids instead of the uids, but it could work similarly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.