比较Smarty中的两个日期 [英] Compare two dates in smarty

查看:90
本文介绍了比较Smarty中的两个日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个日期分别为格式(2014年12月2日和14年12月17日),我想比较聪明地比较这两个日期。

I have two dates in respective format (02-Dec-14 and 17-Dec-14 ) and i want to compare these two dates in smarty.

如何我可以比较这两个日期吗?请帮忙。

How can i compare these two dates ? please help.

预先感谢

推荐答案

如果有例如,以这种方式分配给Smarty的日期:

If you have those dates assigned to Smarty for example this way:

$smarty->assign('date2','02-Dec-14');
$smarty->assign('date1','17-Dec-14');

您可以直接在Smarty中使用 strtotime 函数,例如:

you can use strtotime function directly in Smarty, for example:

{if $date1|strtotime < $date2|strtotime}
    {$date1} is earlier than {$date2}
{elseif $date1|strtotime == $date2|strtotime}
    Both dates are the same
{else}
    {$date2} is earlier than {$date1}
{/if}

这篇关于比较Smarty中的两个日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆