Jump to content

Getting The Current Date And Time In Codeigniter


booxvid

Recommended Posts

 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

Link to comment
Share on other sites

  • 2 weeks later...

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 by keevitaja
Link to comment
Share on other sites

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.