Welcome Guest, Not a member yet? Register   Sign In
date insertion problem
#1

[eluser]dimis[/eluser]
I use Active record to insert some values at a table.
I have also a datetime field. My problem is thatwhen it is 14:00 the field takes the time as it wat at morning (02:00, not 14:00 )! I tried the str_todate of mysql the now() function of CI and the time() of php.
All the same, what is wrong?

I use this
Code:
$value=time();
$data=array(...'datefield'=>$value...)
$this->db->insert($data,'table');
Dimis
#2

[eluser]TheFuzzy0ne[/eluser]
A date and time field (in MySQL, anyway), requires a string in the correct formats, and it's not possible to pass it a timestamp. You can format your timestamp using date(), and then everything should work. You should see this working if you query the database with something like:

INSERT INTO `table_name` ('my_column') VALUES('NOW()');
#3

[eluser]dimis[/eluser]
I do this
$value="now()";
$data=array('datefield'=>$value);
etc but since the date is ok the time is 03 the morning and not 03 the afternoon.
What is wrong?
Dimis
#4

[eluser]Nevio[/eluser]
You can set it like this as well.
Code:
$obj = new stdClass();

$obj->datefield = date('Y-m-d H:i:s');

$this->db->insert('tablename' $obj );
#5

[eluser]TheFuzzy0ne[/eluser]
That was an example. You might need to run the query outside of the AR class for that one to work. It might be escaping things that shouldn't be escaped, but I'm not sure. Seeing if the query runs successfully outside of the AR class should help us figure out if the problem is the AR class or not.

What do you see when you do this:
Code:
echo date('r');




Theme © iAndrew 2016 - Forum software by © MyBB