【发布时间】:2018-07-27 22:09:39
【问题描述】:
我有一个关于 mysql Datetime 格式将日期和时间一起存储在表中的特定问题,所以我已经在表中存储了值,现在我想检索这些值,然后将该时间与当前日期时间进行比较,但事情是大错特错。 这是我到目前为止所尝试的..
<?php
date_default_timezone_set('Asia/Calcutta');
require_once('connect.php');
$query="select matchTime from fixture_list where value1='Mumbai'";
if($result= mysqli_query($con,$query)){
while($row=mysqli_fetch_assoc($result)){
print_r($row);
}
mysqli_free_result($result);
}
//$target = new DateTime('2018-07-27 01:00:00');
$target = new DateTime($query);
$now = new DateTime;
$diff = $target->diff($now);
if ($target > $now) {
echo $diff->format('%a days, %h hours, %i minutes to go');
}
else {
echo $diff->format('%a days, %h hours, %i minutes too late');
}
?>
我唯一的目的是获取可能已存储在数据库中的字符串中的日期时间值并将其传递给 $target 变量,然后与 $now 进行比较,这是我得到的错误“数组([matchTime] = > 2018-07-27 00:00:00 ) 数组 ( [matchTime] => 2018-07-27 00:00:00 ) 数组 ( [matchTime] => 2018-07-28 01:00:00 ) 致命错误:未捕获的异常 'Exception' 带有消息 'DateTime::__construct(): 无法在位置 0 (s) 解析时间字符串(从 fixture_list 中选择 matchTime):在数据库中找不到时区'"
【问题讨论】: