查找格式为' mm / dd / yyyy'的两个日期之间的天数。用PHP

时间:2014-06-26 19:24:06

标签: php mysql date timestamp

我正在获得转换为天数的随机数

CODE

$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 ;

这是随机数字 的 OUTPUTS

  OUTPUT1:  -14566.25566
  OUTPUT2:  1452.33655

1 个答案:

答案 0 :(得分:0)

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

即可
    $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>