booxvid Posted October 1, 2012 Share Posted October 1, 2012 public function create_blog(){ $this->load->view('header'); $this->form_validation->set_rules('blogtitle','Blog Title','required'); $this->form_validation->set_rules('desc','Description','required'); $this->form_validation->set_error_delimiters(' ',''); if($this->form_validation->run()==FALSE){ $this->load->view('view_dashboard_addblog'); } else{ $title =$this->input->post('blogtitle'); $desc = $this->input->post('desc'); $data = array( 'blog_title'=>$title, 'description'=>$desc, 'blog_date'=>CURDATE(), 'blog_time'=>CURTIME()); $this->blog_model->insert_posts($data); echo ""; $this->load->view('view_blog'); } } My problem is, curdate() and curtime() function for mysql doesn't work at all, it says an undefined function, how to get the current date and time in Codeigniter and insert it into my mysql table Quote Link to comment https://forums.phpfreaks.com/topic/268967-getting-the-current-date-and-time-in-codeigniter/ Share on other sites More sharing options...
Mahngiel Posted October 1, 2012 Share Posted October 1, 2012 (edited) You should combine both the date and the time into one datetime column. Then you just use date or CI's mdate: http://codeigniter.c...ate_helper.html ? Edited October 1, 2012 by Mahngiel Quote Link to comment https://forums.phpfreaks.com/topic/268967-getting-the-current-date-and-time-in-codeigniter/#findComment-1382062 Share on other sites More sharing options...
booxvid Posted October 1, 2012 Author Share Posted October 1, 2012 Is there another way that I could separate the date and time because I have two columns in my mysql table the blog_date and blog_time Quote Link to comment https://forums.phpfreaks.com/topic/268967-getting-the-current-date-and-time-in-codeigniter/#findComment-1382063 Share on other sites More sharing options...
Mahngiel Posted October 1, 2012 Share Posted October 1, 2012 (edited) you could, but there's no need for it. if you look at time or date you see that the value for such is calculated in one value. Therefore, it's needless for you to separate the code. Edited October 1, 2012 by Mahngiel Quote Link to comment https://forums.phpfreaks.com/topic/268967-getting-the-current-date-and-time-in-codeigniter/#findComment-1382066 Share on other sites More sharing options...
keevitaja Posted October 9, 2012 Share Posted October 9, 2012 (edited) if you use active records, then adding the date should look something like this: $this->db->set('created', 'NOW()', FALSE)->insert('posts', $data); where table field created is mysql datetime. $data does not contain created at all. Edited October 9, 2012 by keevitaja Quote Link to comment https://forums.phpfreaks.com/topic/268967-getting-the-current-date-and-time-in-codeigniter/#findComment-1383952 Share on other sites More sharing options...
jinijames Posted October 20, 2012 Share Posted October 20, 2012 Inserting current time Codeigniter's active record. $data = array( 'name' => $name , 'email' => $email, 'time' => NOW() ); $this->db->insert('mytable', $data); Quote Link to comment https://forums.phpfreaks.com/topic/268967-getting-the-current-date-and-time-in-codeigniter/#findComment-1386559 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.