• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I add the date with active records, meaning a MySQL NOW() function equivalent?

#1
[eluser]gunnarflax[/eluser]
The title says it all. I tried inserting 'NOW()' as a string but it didn't work so I guess I have insert the date myself in a fitting datetime format. How do I do this?

#2
[eluser]flaky[/eluser]
Code:
$this->db->set('test', 'NOW()', false);        
$this->db->insert('test', $data);

#3
[eluser]InsiteFX[/eluser]
You can also do it like this:
Code:
$now = date("Y-m-d H:i:s");

$data = array(
    'your_date_field_name' => $now
);

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

InsiteFX

#4
[eluser]gunnarflax[/eluser]
Thanks guys! It worked perfectly (both solutions)!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.