$sql = "SELECT lnumber,violation,datetime FROM violators WHERE lnumber='".$lnumber."'";
選擇從我的數據庫三列,並將結果解析成JSONArray和我得到這個結果
{"lnumber":"2","violation":"Beating the red light","datetime":"2017-10-15 13:02:34"}
現在我想做的是如何解析「datetime」字段沒有秒?
下面是完整的代碼:
$sql = "SELECT lnumber,violation,datetime FROM violators WHERE lnumber='".$lnumber."'";
$stmt = $con->prepare($sql);
$stmt->execute();
$stmt->bind_result($lnumber, $violation, $datetime);
while($stmt->fetch())
{
$temp = [
'lnumber'=>$lnumber,
'violation'=>$violation,
'datetime'=>$datetime
];
array_push($result, $temp);
}
echo json_encode($result);
如何實現這一目標?通過做這個? '$ sql =「SELECT lnumber,violation,DATE_FORMAT(」2017-10-15 13:52:35「,」%Y-%m-%d%H:%i「)違規者WHERE lnumber ='」。$ lnumber。「'」;'?這是正確的嗎? –
是的,但用日期時間表格列替換日期文本,如下所示: DATE_FORMAT(datetime,「%Y-%m-%d%H:%i」) – Keith