我正在使用 CodeIgniter 2.1.x 和 MySQL。
我在使用 mysql 列类型 DATETIME
之间发现了很多建议。和 TIMESTAMP
,但我不确定哪个真正适合用于我想要构建的内容。
我有一个应用程序,用户可以在其中通过 <form></form>
向谷歌地图添加标记。 .
每次提交标记后,应为 mysql 的列 date_created
记录当前时间。和 date_end
使用此函数应该是 +1day:
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());
}
...
}
}
但是当我使用设置为 TIMESTAMP
的列类型时,它永远不会正确更新或 DATETIME
.
有什么建议我在这里做错了吗?
最佳答案
如果 now()
函数存在于 CodeIgniter 上(它不存在于 vanilla PHP 上),则检查它的输出是否符合以下格式:Y-m-d H:i:s
,否则,这个问题可以帮助你:Inserting NOW() into Database with CodeIgniter's Active Record , 你也可以使用 PHP standard date and time functions而不是 now()
关于php - 如何在 MySQL 和 PHP 中处理日期和时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18451359/