dongyi5425 2013-07-16 14:59
浏览 56
已采纳

插入日期有时会插入全部0

i have a column in my database for the date a new record was added, it's set with the following code:

    $dateset = date("Y-m-d");
    $q = "INSERT INTO appts (date_set) VALUES ('$dateset')";

this is working about 80% of the time, is there any reason that randomly it will add the date as "0000-00-00"?

  • 写回答

3条回答 默认 最新

  • douai2499 2013-07-16 15:14
    关注

    You should check type of field 'date_set'.

    • if type is DATE you have to use:
    
        $dateset =  date("Y-m-d");
    
    
    • if type is DATETIME you have to use:
    
        $dateset =  date("Y-m-d H:i:s");
        //It is correct, but database push after time 00:00:00 (but it depends on the settings of the database)
        //$dateset =  date("Y-m-d"); 
    
    
    • if type is TIMESTAMP you have to use:
    
        $dateset =  time();
    
    

    Try use sql:

    
        $q = "INSERT INTO appts (date_set) VALUES (NOW())";
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器