Jump to content

Archived

This topic is now archived and is closed to further replies.

booxvid

Getting The Current Date And Time In Codeigniter

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Inserting current time Codeigniter's active record.

 

$data = array(

'name' => $name ,

'email' => $email,

'time' => NOW()

);

$this->db->insert('mytable', $data);

Share this post


Link to post
Share on other sites

×
×
  • 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.