Welcome Guest, Not a member yet? Register   Sign In
Inserting NOW() into Database with Active Record
#1

[eluser]Gwarrior[/eluser]
This should be very simple, but I cannot figure out how to insert a current_timestamp via ActiveRecord. Obviously since "now()" is a SQL function, I can't just use a variable in the array (ex: $data['date'] = NOW()Wink.

So my question is, how is this accomplished?

Thanks!
#2

[eluser]pmoroom[/eluser]
Couldn't you just use curtime() or something like this.....

$this->field1 = $this->input->post('var');
$this->fieldname= date('Y-m-d, g:i:a');
$this->db->insert('tablename', $this);

You get the point.
#3

[eluser]jedd[/eluser]
The major problem with that approach is that it sets the time in your database to the time that your php environment thinks it is. For many occasions this may be acceptably rough, but it's not optimal.
#4

[eluser]pmoroom[/eluser]
[quote author="jedd" date="1251523427"]The major problem with that approach is that it sets the time your database to the time that your php environment thinks it is. For many occasions this may be acceptably rough, but it's not optimal.[/quote]

Understand your point and that is why I gave him two options. His choice I suppose.
#5

[eluser]Armchair Samurai[/eluser]
Use db->set() with the third parameter set to false, as mentioned in the User Guide
Code:
$this->db->set('date', 'NOW()', FALSE);
#6

[eluser]Gwarrior[/eluser]
Thanks everyone!
#7

[eluser]InsiteFX[/eluser]
It also depends on if you are setting the time for the users time or the server time.

Enjoy
InsiteFX




Theme © iAndrew 2016 - Forum software by © MyBB