1

I'd like to work out the age of someone on the date of an Activity. In SearchKit, I've used Arithmetic to subtract the Birth Date from the Activity Date and this almost works, but it ignores the day/month.

I've tried using the rewrite option to put the date into a different format and although it doesn't break it, it's still only using the year for the calculation.

Is this a bug or is there a rewrite that allows me to put it the dates into timestamps?

Screenshot of arithmetic in SearchKit

1 Answer 1

3

If you use the transformation "DATE days between two dates", then you can do a rewrite in the display of {math equation="floor([DATEDIFF_Contact_ActivityContact_Activity_01_activity_date_time_birth_date] / 365)"}. It won't be 100% accurate for leap years etc, but depends if you need that.

If you want more control and you're using smarty 3+, you can do something like this in a rewrite:

{assign var=adate value='[Contact_ActivityContact_Activity_01.activity_date_time]'|date_format:'U'}{assign var=bdate value='[birth_date]'|date_format:'U'}Activity Date: [Contact_ActivityContact_Activity_01.activity_date_time] therefore age is {math equation="floor((a - b)/86400/365)" a=$adate b=$bdate}

(In smarty 3+ using date_format with a non-% format specifier doesn't have the php8/strftime deprecation problem.)

1
  • Awesome, thanks for this! That's worked a treat Commented Jul 10 at 14:35

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.