I have searched but couldn't find an answer. I just created a D7 install and activated Views and the Date module.
Inside the Date module you can configure fields that if people fill in their birthday it will display their age in their profile.
So far all goes well, however I want to create a View in which there is an exposed filter that allows people to search ages e.g. search from 35-55 years.

I somehow lack the experience on this field with regard to Views and wonder if someone could point me in the right direction. I don't want to install a whole range of modules and assume this must be possible with Views?

Comments

Vaibhavi Soni’s picture

You need to alter views query like this way.

You want to get results based on search ages then you can calculate birth date like this way. i.e. 35 - 55. Extract "35" and "55" from search string.

$birthdatestart =  date('Y-m-d', strtotime('-55 years'));
$birthdateend =  date('Y-m-d', strtotime('-35 years'));

It will return two date range and pass it in view query.

You can alter view query with $birthdatestart and $birthdateend.

Hope this helps you.

Thanks!

Snehal Brahmbhatt’s picture

You can use Views age filter module for your purpose.

Thanks,
Snehal Brahmbhatt | AddWeb Solution
https://www.drupal.org/user/3147795/track

renatog’s picture

Status: Active » Reviewed & tested by the community

Hi guys, thank you for help.

I checked and both solutions are valid to solve the problem.

Thank you guys for your contributions.

Best,

renatog’s picture

Status: Reviewed & tested by the community » Fixed

@Zarevac, any question please post for us

Best,

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.