简体   繁体   English

Smarty MySQL日期+ 1天

[英]Smarty mysql date + 1 day

I have a variable that give me the date from mysql: 我有一个变量,可以给我mysql的日期:

{row.date} 

How can i add now 1 day to this? 我现在该如何添加1天?

Exampe: row.date = 2015-07-23 and i wish = 2015-07-24 范例:row.date = 2015-07-23,我希望= 2015-07-24

Thanks in advance. 提前致谢。

You can use Date functions to do this. 您可以使用日期函数来执行此操作。 Here is the way to achieve this: 这是实现此目的的方法:

date_add('2015-07-23', Interval 1 Day);

You can replace "2015-07-23" to column name which contains date in your select query. 您可以将“ 2015-07-23”替换为包含所选查询中日期的列名称。

In Mysql itself you can get like this I would prefer this rather doing in php 在Mysql本身中,您可以像这样,而不是在php中,我更愿意这样做

SELECT DATE_ADD(date, INTERVAL 1 DAY) FROM table;

or 要么

$startDate = $row['date']; // 2015-07-23
echo date("Y-m-d", strtotime("$startDate +1 days"));

If you really want this done in your Smarty template, then you can archive it this way: 如果您确实希望在Smarty模板中完成此操作,则可以通过以下方式将其存档:

{"$row.date +1 Days"|date_format:'Y-m-d'}

However, I would usually advise against doing too much math and other logic in a Smarty template. 但是,我通常建议不要在Smarty模板中进行过多的数学运算和其他逻辑运算。 In most use cases, it would be better to do the math somewhere within your (php) application and then display the result within the template. 在大多数使用情况下,最好在(php)应用程序中的某个位置进行数学运算,然后在模板中显示结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM