douweng3564 2017-10-05 17:24
浏览 721
已采纳

SQL - DATE类型格式为YYYY-MM-DD,但UPDATE格式为YYYYMMDD

I have set up my database and set a field with the DATE-Type. When I look into my database the format is: YYYY-MM-DD but I can only update this field when I insert this format: YYYYMMDD with my statement.

Why is the insert format a other one than the DATE-Type format?

My PDO statement:

$stmt = $db->prepare("UPDATE mitarbeiter SET abwesend_von = :abwesend_von, abwesend_bis = :abwesend_bis WHERE id = :id");
      $stmt->execute(array(
        ':abwesend_von' => $_POST['abwesend_von'],
        ':abwesend_bis' => $_POST['abwesend_bis'],
        ':id' => $_POST['mitarbeiternummer_abwesenheit']
      ));

My POST Data:

mitarbeiternummer_abwesenheit:26
abwesend_von:20171001
abwesend_bis:20171031

Some informations:

  • Database: Server Version: 5.6.19-67.0-log
  • Database: MySQL-Client-Version: 5.1.61
  • Programming language is PHP
  • 写回答

2条回答 默认 最新

  • douchangmian0305 2017-10-05 19:26
    关注

    Date and time values can be represented in several formats, such as quoted strings or as numbers, depending on the exact type of the value and other factors. For example, in contexts where MySQL expects a date, it interprets any of '2015-07-21', '20150721', and 20150721 as a date.

    source

    The parameterized mechanisms of the php library could be interpreting the parameter as something other than a string, resulting in the query being ... SET abwesend_von = 2017-01-05 ... which is equivalent to ... SET abwesend_von = 2011 ...; instead of ... SET abwesend_von = '2017-01-05' ...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大