我有一个显示数据库数据的表。例如,像这样:
<table>
<tr>
<th>Title</th>
<th>Date</th>
<th>Start Time</th>
<th>End Time</th>
</tr>
<tr>
<td>French</td>
<td>21 December 1992</td>
<td>23:00</td>
<td>05:00</td>
</tr>
我想知道如何显示我开始之前剩下的时间。例如:法语在2小时内开始。我知道我现在需要时间,但我不确定该怎么做。
修改
如果数据库中有多个数据,我也想知道如何显示最早的数据。
$sql = DB::getInstance()->get('sessions', array('MONTH(date)','=' ,$userSelection));
//mysql_db_query('nio', "SELECT DATE");
echo "<table class='table table-hover'style='color: orange' > "
."<thead>
<tr>
<th>Title</th>
<th>Date</th>
<th>Start Time</th>
<th>End Time</th>
</tr>
</thead>
<tbody>";
if(!$sql->count()){
echo 'No data';
}else {
foreach ($sql->results() as $sql){
echo "<tr style='background-color: black'>";
echo "<td><a href = session-options.php>" . $sql->title . "</a></td>";
echo "<td>" . $sql->date . "</td>";
echo "<td>" . $sql->start_time . "</td>";
echo "<td>" . $sql->end_time . "</td>";
echo "</tr>";
?>
<?php }}echo" </tbody>";
echo" </table>";
}
?>
它在网页上显示为一个表格。这就是它如何添加到db:
try {
$user->createSession(array(
'title' => Input::get('title'),
'date' => Input::get('date'),
'start_time' => Input::get('timepicker1'),
'end_time' => Input::get('timepicker2'),
'passcode' => (Input::get('passcode')),
'username' => $user->data()->username,
'module' => $module
));
<div class="input-group date" data-date-format="yyyy-mm-dd">
<input type="text" class="form-control" name="date" id="date" placeholder="Choose Date:">
<span class="input-group-addon">
<i class="glyphicon glyphicon-th"></i>
</span>
</div> <br>
<div class="row">
<div class="col-lg-5"><div class="input-group">
<div class="input-append bootstrap-timepicker top-margin"> Start Time:
<input id="timepicker1" type="text" name="timepicker1">
<span class="add-on"><i class="glyphicon glyphicon-time"></i></span>
</div>
</div>
</div>
<div class="col-lg-5">
<div class="input-group">
<div class="input-append bootstrap-timepicker top-margin"> End Time:
<input id="timepicker2" type="text" name="timepicker2">
<span class="add-on">
<i class="glyphicon glyphicon-time"></i></span>
</div>
</div>
答案 0 :(得分:1)
尝试以下代码。您可以使用&#39; $ sql-&gt; start_time&#39;取代&#39; $ start_time&#39;和&#39; $ sql-&gt; date&#39;取代&#39; $ start_date&#39;。检查你的default_timezone。
date_default_timezone_set("Asia/Kolkata");
$start_date = '2015-03-02';
$start_time = '04:15:58';
$current_datetime = date('Y-m-d H:i:s', time());
$start_datetime = new DateTime($start_date.' '.$start_time);
$end_datetime = new DateTime($current_datetime);
$since_start = $start_datetime->diff($end_datetime);
echo ($since_start->days * 24)+$since_start->h.' hours / ';
echo $since_start->i.' minutes / ';
echo $since_start->s.' seconds remaining';
上面的代码给出了输出:
剩余2小时/ 22分钟/ 30秒
您可以根据自己的要求进行编辑。