7

I have an entry with a dateOfBirth Date/Time Field.

Is it possible to calculate the current age from that field?

I can't find a craft/twig function/filter to calculate the difference between 2 dates.

12

Craft's Date/Time field extends PHP's DateTime class so (since 5.3.0) you can use the Diff method like so:

yourDateTimeField.diff(now).format('%y')

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.