Php 从两个日期开始使用到期条

Php 从两个日期开始使用到期条,php,sql,Php,Sql,您可以在Mysql中自己进行计算,而不用PHP进行计算。 这里我给出了2014-1-21作为用户的加入日期,在您的查询中,您可以给出字段名称 然后运行查询,您将在几天内得到差异。 您可以这样尝试: <td valign="bottom"> <div style="width: 205px;height: 21px;border: 1px solid;"> <div style="height: 21px;background-color:#5f5

您可以在Mysql中自己进行计算,而不用PHP进行计算。
这里我给出了
2014-1-21
作为用户的加入日期,在您的查询中,您可以给出字段名称 然后运行查询,您将在几天内得到差异。 您可以这样尝试:

<td valign="bottom"> 
   <div style="width: 205px;height: 21px;border: 1px solid;">
      <div style="height: 21px;background-color:#5f5f5f; width:<?=$width?>"></div>
      </div><br>
      <span style="font-size:11px;">*Valid for 1 year from the date of purchase</span>
 </td>
SELECT DATEDIFF(now(),'2014-1-21 00:00:00') as Diff from tableName
有关此功能的详细信息:

如果你想要两个日期之间的月差。您可以这样做:

<td valign="bottom"> 
   <div style="width: 205px;height: 21px;border: 1px solid;">
      <div style="height: 21px;background-color:#5f5f5f; width:<?=$width?>"></div>
      </div><br>
      <span style="font-size:11px;">*Valid for 1 year from the date of purchase</span>
 </td>
SELECT DATEDIFF(now(),'2014-1-21 00:00:00') as Diff from tableName
更多信息


Sql FIDLE:

您需要查看PHP的日期/时间函数,特别是
diff
:您使用的是什么数据库?MySQL,MSSQL?这里有一个非常有帮助的问题:您使用的是什么数据库?因为您可以直接查询unix时间,然后执行一个简单的整数差分,避免PHP提供的难看的datetime差分。如果他想知道已经过去的月数,这会起作用吗?看起来DateDiff返回了天?就算我可能错了。事实上,很难理解这个问题,因为问题会有所不同。