Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert Current DateTime in Codeigniter 3.0.6

I'm trying to store user signup date and time using codeigniter 3.0.6 and using

NOW()

as

 $this->db->set('user_nicename', $nameVar);
   $this->db->set('user_login', $emailVar);
   $this->db->set('user_pass', $passwordVar);
   $this->db->set('user_registered', 'NOW()');
   $this->db->insert('doc_users');

but it is not storing date time in database

see database image

like image 444
Kashif Latif Avatar asked Dec 22 '15 11:12

Kashif Latif


2 Answers

use date() like this

date('Y-m-d H:i:s'); # output 2015-12-22 16:41:25

Final Code is

date_default_timezone_set('Asia/Karachi'); # add your city to set local time zone
$now = date('Y-m-d H:i:s');

$this->db->set('user_nicename', $nameVar);
$this->db->set('user_login', $emailVar);
$this->db->set('user_pass', $passwordVar);
$this->db->set('user_registered', $now);
$this->db->insert('doc_users');
like image 78
Abdulla Nilam Avatar answered Sep 28 '22 05:09

Abdulla Nilam


this works for me in Codeigniter 3.0.6

$this->db->set('user_registered', 'NOW()', FALSE);
like image 27
Kashif Latif Avatar answered Sep 28 '22 04:09

Kashif Latif