php - 如果在智能 php 中创建带有日期的语句
问题描述
如何在 smarty php 中创建验证,如果该值在指定日期的 30 天内出现,则允许该值出现?
在数组中:
Array (4)
0 => Array (13)
id => 6496
invoicenum => 6496
datecreated => "08/09/2020"
normalisedDateCreated => "2020-09-08"
我不知道什么是理想的领域,但我们可以使用datecreated
or normalisedDateCreated
。
它看起来像这样:
{if $invoice.datecreated ... } if it is more than 30 days from the current date it should display NO
YES
{else}
NO
{/if}
解决方案
您可以使用获取当前日期$smarty.now
,然后从中减去 30 天。
{if "$smarty.now -30 Days"|date_format:'%Y-%m-%d' < $invoice.normalisedDateCreated}
YES
{else}
NO
{/if}
但是,如果可以只从当前日期前 30 天的 php 传递另一个变量,则会简化它。
@zecaluis 提出的另一个解决方案
{if strtotime($invoice.normalisedDateCreated) > strtotime('-30 days')}
推荐阅读
- azure-devops - VSTS - 部署多个 Web 应用程序
- websphere-liberty - IBM JSR 352 作业日志为空
- amazon-web-services - AWS EC2 RHEL 从 6 升级到 7
- python-3.x - 在服务器端从 bash 执行 python 时找不到 Python 模块
- javascript - 尝试在没有 OpenGL 的情况下用 Java 制作立方体
- javascript - 我可以将属性(或某种等价物)分配给 Javascript 变量吗?包含示例代码
- backend - 我应该如何制作 URL 路由器?
- php - 从用希伯来语编写的 vbulletin 数据库获取数据,得到奇怪的编码
- tensorflow - 当我在新的自定义 C++ 操作中调用标准操作(例如 MatMul)时,Bazel 返回错误
- sql - WITH clause sub-query has non-unique column names