duanjian4150 2013-08-26 19:14
浏览 49

如何处理MySQL和PHP中的日期和时间?

I'am using a CodeIgniter 2.1.x and MySQL.
I found a lot of advices between using mysql column type DATETIME and TIMESTAMP, but I'm not sure which is really correct to use with what I want to build.

I have an application, where user can add markers to google maps throught the <form></form>. After each marker submission, a current time should be recorded for the mysql's column date_created and date_end which should be +1day by using this function:

class Maps extends CI_Controller{
    ...
    public function marker($action = NULL, $slug = 'marker_add'){
        ...
        if($this->form_validation->run() == TRUE){
            $tomorrow = now() + 86400;
            $data_markers = array(
                'tid'           => $this->input->post('formMarkType'),
                'lat'           => $this->input->post('formMarkLat'),
                'lng'           => $this->input->post('formMarkLng'),
                'state'         => 1,
                'description'   => $this->input->post('formMarkDescription'),
                'date_end'      => $tomorrow
            );
            $this->map_model->markers_add($data_markers);
            redirect(site_url());
        }
        ...
    }

}

But it never updates correctly when I'am using column types set as TIMESTAMP or DATETIME.

Any suggestion what I'm doing wrong here ?

  • 写回答

3条回答 默认 最新

  • dragon012100 2013-08-26 19:28
    关注

    If the now() function exists on CodeIgniter (it doesn't on vanilla PHP), then check that it's output matches the following format: Y-m-d H:i:s, otherwise, this question could help you: Inserting NOW() into Database with CodeIgniter's Active Record, also, you can use PHP standard date and time functions instead of now()

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题