Need to show Date Difference in tpl file

I need to show date difference in the foreach loop smarty(tpl) , but when i do strtotime it will give me NULL result , can anyone please help me out, here is my code

{assign var="date1" value=$field->dob}
{php}
$date1 = $this->get_template_vars('date1');
$diff = abs(time() - strtotime((string)$date1));
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
printf("%d years, %d months\n", $years, $months);
{/php}

Thanks in advanced.

Can you print $date1 and check what is in there? Does the format look ok?

$date1 is showing correct date via $this->get_template_vars(‘date1’); But when i do this strtotime($date1) , this will replace the value NULL in date1.

the format is date 12/11/2008

Try to read the details of the docs:

https://www.php.net/manual/en/function.strtotime.php

Are you sure it’s returning NULL? Isn’t it FALSE, or -1?

Check the timezone, the warnings in the logs, try passing it a different format, etc.

ok thanks for the quick reply , appreciated.