CodeIgniter Forums

Full Version: Insert with active record. Cant insert with a date field.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]carlosgoce[/eluser]
Hello everyone,

i'm trying again to use active record because my tabes are really big, like 70 fields each, and active record really helps.

The thing is, i have a object with all of the var names (fields of the table) and it works... except the date fields.

I explain with code, it's always better:

Here my field
Code:
var $date = '2013,03,18';

The insert looks like
Code:
INSERT INTO table (date) VALUES ('2013,03,18')
but it should looks like
Code:
INSERT INTO table (date) VALUES (DATE('2013,03,18'))

How can i get that?

Thank you!

Btw i'm using dbase with odbc... there are things that i can't use but if i can get this working it will be a big help for me.

Oh, and... can i use active record mixed with standard querys?

Fixed with: $this->db->set('fecha', 'DATE(2000,01,01)', FALSE);

El Forum

[eluser]rwestergren[/eluser]
You can't mix active record and stand queries. You look like you're on the right track, though. Have you tried this:

Code:
$data['date'] = "DATE('2013,03,18')";

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

El Forum

[eluser]carlosgoce[/eluser]
[quote author="rwestergren" date="1363644650"]You can't mix active record and stand queries. You look like you're on the right track, though. Have you tried this:

Code:
$data['date'] = "DATE('2013,03,18')";

$this->db->insert('table', $data);
[/quote]

No, but i'll try soon... thank you

El Forum

[eluser]TheFuzzy0ne[/eluser]
Why not pass the date into the query in the correct format?

Code:
$this->db->insert('table', array(
    'date' => date('Y-m-d', mktime(0, 0, 0, $month, $day, $year))
));