Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Using template variables in PHP for date difference

 
Post new topic   Reply to topic    Smarty Forum Index -> Tips and Tricks
View previous topic :: View next topic  
Author Message
saiful
Smarty n00b


Joined: 19 Jun 2014
Posts: 3

PostPosted: Thu Jun 19, 2014 8:27 am    Post subject: Using template variables in PHP for date difference Reply with quote

Hello every one, hope all of you passing nice days. I need a small help.
I am very new in smapty. I am using smarty with codeigniter first time. Now i have a problem to find the difference between two date. Join date and resign comes from a for loop. I attach my code block here.
----------------------------------------------------------------------------------
{foreach $data.exp_info as $exp}
{assign var="ex_join_year" value="{$exp->ex_join_year}"}
{assign var="ex_resign_year" value="{$exp->ex_resign_year}"}
{assign var="ex_join_month" value="{$exp->ex_join_month}"}
{assign var="ex_resign_month" value="{$exp->ex_resign_month}"}

{php}

$date1 = $smarty->get_template_vars('ex_join_year');
$date2 = $smarty->get_template_vars('ex_resign_year');

//$date1 = "2007-Jan"; sample date
//$date2 = "2007-feb"; sample date

$diff = abs(strtotime($date2) - strtotime($date1));

$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));

printf("%d years, %d months\n", $years, $months);
{/php}
{/foreach}

---------------------------------------------------------------------------------
Thanks every one
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Tips and Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP