Skip to content

Instantly share code, notes, and snippets.

@mikedfunk
Created November 16, 2011 19:02
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mikedfunk/1370989 to your computer and use it in GitHub Desktop.
Save mikedfunk/1370989 to your computer and use it in GitHub Desktop.
Using MySQL NOW() in Codeigniter
<?php
// Using MySQL NOW() in Codeigniter
// by daveganley
// There are two easy ways to do this
// With NOW()
$data = array(
'field_name' => 'some_data'
);
$this->db->set('date_field_name', 'NOW()', FALSE);
$this->db->insert('table_name', $data);
// The FALSE in the set method prevents the NOW() being escaped
// Without NOW()
$now = date('Y-m-d H:i:s');
$data = array(
'field_name' => 'some_data',
'date_field_name' => $now
);
$this->db->insert('table_name', $data);
@dalveernayak
Copy link

field_name

@dalveernayak
Copy link

Commented 5 minutes ago

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment