查找格式为'的两个日期之间的天数;年月日';在PHP中
我得到了转换为天的随机数 代码查找格式为'的两个日期之间的天数;年月日';在PHP中,php,mysql,date,timestamp,Php,Mysql,Date,Timestamp,我得到了转换为天的随机数 代码 $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);
$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
其他一切都很好,只要加上这个
$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>
$diff=$futureDateTimestamp-$now;
$days=intval($diff/86400);
//找到剩下的时间
$rem_秒=$diff%86400
$rem_hr=intval($rem_sec/3600);
你总共还有几个小时
1。不要将日期存储为字符串,将其存储为日期2。什么是myDateValue的有效值?但我仍然使用strtotime,myDateValue是未来的日期,因为2014年12月25日您的代码对我有效。很可能您的某些日期值不正确。这是将日期存储为字符串的常见副作用。这意味着,Datetimepicker将值取为MM/DD/YYYY,因此即使我将其转换为时间戳,我也会得到相同的时间戳值,甚至在将其放入数据库或稍后转换之前