使用 Bootstrap-Editable 时日期时间更新出错

Datetime update goes wrong when using Bootstrap-Editable

我正在尝试更新 sql 日期时间。我只是想更新时间并为 substr() 准备一些脚本。现在,当我更新小时和分钟时 (d) 在第一次编辑中重置为 1,在第二次编辑中重置为 0。

我正在使用由 php 和 bootstrap-editable 生成的 html table 使用 Js 和 [=34 编辑行=].

为什么数据库中的日期 return 先是 01 然后是 00?

例如。 2012-02-23 00:00:00 在第一次更新中变为 2012-02-01 00:00:00。

HTML

<a href='#' id='".$row['id']."' class='usr_stamp_out' data-name='usr_stamp_out' data-type='text' data-pk='".$row['id']."' data-url='php/time.php' data-title='Stämpla ut..'>".substr($row['usr_stamp_out'],11,5)."</a>

PHP

$id = $_POST['pk'];
$updated_usr_stamp_out = $_POST['value'];

if($row){
    //Substring datetime to 0000-00-00
    $usr_stamp_out_date = substr($row['usr_stamp_out'],0,9);

    //Add old date to updated time
    $new_usr_stamp_out = $usr_stamp_out_date." ".$updated_usr_stamp_out;

    //Prepare query
    $query = "UPDATE table SET usr_stamp_out = :usr_stamp_out WHERE id = :id";

    // Security measures
    $query_params = array(':id' => $id,':usr_stamp_out' => $new_usr_stamp_out);

    //Connect and execute
    try {  
        $stmt = $db->prepare($query); 
        $result = $stmt->execute($query_params); 
    } 
    catch(PDOException $ex){
        die("Failed to run query: " . $ex->getMessage());
    }
}

$usr_stamp_out_date = substr($row['usr_stamp_out'],0,9); 仅获取日期的前九个字符,而不是获得正确日期所需的十个字符。

$usr_stamp_out_date = substr($row['usr_stamp_out'],0,10);

另一种方法是使用 PHP 的日期功能获取日期:

$usr_stamp_out_date = date('Y-m-d', strtotime($row['usr_stamp_out']));