我有一个返回
的日期选择器 $Time: 09:00
(这是字符串)
$Date: 2014-05-01
(这是字符串)
我想将它们组合成字符串来实现:
$From: 2014-05-02T09:00:00
所以我需要$From = $Date + 'T' + $Time + ':00'
为什么这不起作用:
include 'Db.php';
$dateFrom = '2014-05-02' . 'T' . '09:00' . ':00';
$dateTo = '2014-05-02' . 'T' . '14:00' . ':00';
$con = DbConnect();
$sql = "insert into calendar(ContactName, DateFrom, DateTo, ContactPhone) values ('User', '".$dateFrom."', '".$dateTo."', '1234567' )";
print(json_encode(mysqli_affected_rows($con)));
mysqli_close($con);
答案 0 :(得分:1)
它很简单,你只需要使用"。"在" +"
$From = $Date . 'T' . $Time . ':00'
编辑:
include 'Db.php';
$dateFrom = '2014-05-02' . 'T' . '09:00' . ':00';
$dateTo = '2014-05-02' . 'T' . '14:00' . ':00';
$con = DbConnect();
$sql = "insert into calendar(ContactName, DateFrom, DateTo, ContactPhone) values ('User', '".$dateFrom."', '".$dateTo."', '1234567' )";
if(mysqli_query($con,$sql)){
print(json_encode(mysqli_affected_rows($con)));
mysqli_close($con);
}