Answers.Body: <p>If you use the transformation &quot;DATE days between two dates&quot;, then you can do a rewrite in the display of <code>{math equation=&quot;floor([DATEDIFF_Contact_ActivityContact_Activity_01_activity_date_time_birth_date] / 365)&quot;}</code>. It won't be 100% accurate for leap years etc, but depends if you need that.</p>
  <p>If you want more control and you're using smarty 3+, you can do something like this in a rewrite:</p>
  <p><code>{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=&quot;floor((a - b)/86400/365)&quot; a=$adate b=$bdate}</code></p>
  <p>(In smarty 3+ using date_format with a non-% format specifier doesn't have the php8/strftime deprecation problem.)</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-07-10T14:35:57.200Z
Answers.Text: Awesome, thanks for this! That's worked a treat
Answers.UserDisplayName: Rose Lanigan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-07-05T14:11:38.223Z
Answers.LastActivityDate: 2024-07-05T14:11:38.223Z
Answers.UserDisplayName: Demerit
Body: <p>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.</p>
  <p>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.</p>
  <p>Is this a bug or is there a rewrite that allows me to put it the dates into timestamps?</p>
  <p><a href="https://i.sstatic.net/zdiTEG5n.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/zdiTEG5n.png" alt="Screenshot of arithmetic in SearchKit" /></a></p>
  
Tags: <searchkit><dates>
Title: Using Arithmetic with Dates in SearchKit
ThreadText: # Using Arithmetic with Dates in SearchKit
  
  (Asked by: username_0 on 2024-07-05)
  
  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](https://i.sstatic.net/zdiTEG5n.png)](https://i.sstatic.net/zdiTEG5n.png)
  
  **Tags:** searchkit, dates
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-07-05. Score: 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.)
  
  > **Comments:**
  > **username_0**: Awesome, thanks for this! That's worked a treat  
  
  ---
  
  