duanhuiqing9528 2016-11-18 17:50
浏览 25
已采纳

php更改了数据库日期值

review this piece of code:

$values = $mysqli->query("select * from `my_table`");
while($value = $values->fetch_array()) {
   print_array($value);
}

however one column having a date structure does this:

[8] => 2016-11-20
[date] => 2016-10-02 15:52:18

As you can see, 8 is having a different value as date however, they should be the same value because it is the same column in the same row. How can 'date' be changed?

the expected result = 2016-11-20 because that is the same value as stored in my database

info about my table: it has 8 different columns containing all kind of things that do work. the 8th field is named 'date' and has type 'DATE'

concluding: somehow my output is in datetime (wrong time and date though) while it should be DATE

  • 写回答

1条回答 默认 最新

  • douxianglu4370 2016-11-18 18:19
    关注

    Depening on your version of MySQL, there seems to be some ambiguity (to me at least) about the "DATE" column type. From your results it appears that DATE is an alias for DATETIME, but MySQL does some truncation on the result.

    So, a work around.. Don't user * , instead specify your column names , and on column 8, use the DATE function to retireve only the date portion.

    select `col1`, `col2`, ..., DATE(`col8`) from `my_table`");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 questasim仿真报错
  • ¥15 寻找电脑攻防的导师,有问题请教一下。
  • ¥20 微信同是win11,我的电脑安装不了pageoffice,一直无法打开
  • ¥15 这个界面我通过postman请求不到,但是通过浏览器可以正常访问
  • ¥15 动态规划算法实现背包问题
  • ¥15 wpf程序使用过程中异常奔溃
  • ¥15 多目标优化算法在与其他算法数据对比结果判断
  • ¥15 CPTN和EAST,主干网络是VGG16,请问在ICDAR2015数据集上训练之后,CPTN和EAST模型的大小为多少
  • ¥15 按颜色进行点云分割-python
  • ¥15 Matlab如何实现汽车变道切入场景的批量仿真