I want to have a "birthdate" field for my users. It should be optional to enter a year or a date. If a year is selected I want to display the age. If a date is entered I want to show the birthdate.

If I use the date field and make it optional I can have empty default values. However, as soon as I enter a year it requires the date and month too and vise versa.

Any solutions?

1 Answer 1


I would define 3 optional selects:
- Year (now() to now() - 100)
- Month (1-12)
- Day (1-31)

Then in a hook_node_validate() I would check if only the year is provided or a full date. Also don't forget to verify if the date is valid (like Feb, 31...) using checkdate( int $month , int $day , int $year ).

Then create a field template to either display the age or a birthdate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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