我正在将时间字段插入到表中,其中该时间字段在数据库中的长度为6。
我在表单中使用Tempos Dominus Bootstrap库
<div class="form-group">
<label for="time">Hora</label>
<div class="input-group date" id="datetimepicker3" data-target-input="nearest">
<input type="text" name="time" class="form-control datetimepicker-input" data-target="#datetimepicker3"/>
<div class="input-group-append" data-target="#datetimepicker3" data-toggle="datetimepicker">
<div class="input-group-text"><i class="fa fa-clock-o"></i></div>
</div>
</div>
</div>
$time = strtotime($_POST['time']);
$time = date('HH:mm', $time);
//insere novo turno na base de dados
$sql = "INSERT INTO shifts (name, origin, destination, transport_number, status, date, time) VALUES (?,?,?,?,?,?,?)";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: ../shifts.php?error=sqlerror");
exit();
} else {
mysqli_stmt_bind_param($stmt, "sssssss", $username, $origin, $destination, $transport, $status, $date, $time);
mysqli_stmt_execute($stmt);
header("Location: ../shifts.php?newrecord=success");
exit();
}
我尝试使用H:i:s格式,但似乎不起作用。
11:07:00
11:07:00.000000
感谢您的帮助。
答案 0 :(得分:1)
列的格式为TIME(6)。例如,here,
TIME(N)是一列,其中N是代表整数的整数 小数部分(秒),最多6位数字。
或者换句话说,TIME(6)表示点后的六个零。我相信要获得结果,您的列应具有TIME(0)或仅TIME作为数据类型,否则您将必须舍弃零。