[mysql]查找格式,mm/dd/yyyy ' 在 PHP 中的两个日期之间的天数

标签: MySQL PHP
发布时间: 2017/1/9 21:32:08
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我相处随机数字将转换为天

代码

$myDateValue = sql::readOne("SELECT `myDateValue` FROM table WHERE id = Value");
// the myDateValue is collected as TEXT in MYSQL

$futureDate =$myDateValue->myDateValue;
$now =time();
$futureDateTimestamp = strtotime($futureDate);

$days = number_format(($futureDateTimestamp - $now)/86400,2,'.',' '); 

echo $days ;

这给随机数字输出

  OUTPUT1:  -14566.25566
  OUTPUT2:  1452.33655

解决方法 1:

其他一切都很好,只需添加这

    $diff = $futureDateTimestamp - $now;
    $days = intval($diff /86400) ;
    // to find the remaining hours
    $rem_sec = $diff % 86400
    $rem_hr = intval ($rem_sec/3600);

<p> You have total of <?php echo $days .'days and'  $rem_hr ?> hours Left  </p>
赞助商