DATETIME woes :(

Associate
Joined
19 Jul 2006
Posts
1,847
OK I have a mySQL table that has a few date columns in, it is set up so that there is a create date and a update date. The UpdateTimeStamp column updates automatically using the on update CURRENT_TIMESTAMP Attributes, Its my understanding that you can only use a one timestamp in this special way, and this is fine.

So on the createdate column I need to manually add the date that the record was created its a datetime column.

I have read that you can use the NOW() command for this. However using it in the following brings me a undefined function error. I have tried it as just 'CreateDate' => NOW(), which gives the same error or using 'CreateDate' => set_value('NOW()'), does not produce an error but no value is entered into the database for this column.

PHP:
form_data = array(
    'ClientID' => set_value('ClientID'),
    'ClientReference' => set_value('ClientReference'),
    'CreateDate' => set_value(NOW()),
    'Gender' => set_value('Gender'),
    'MaritalStatus' => set_value('MaritalStatus'),
    'ContactNumber' => set_value('ContactNumber'),
    'Nationality' => set_value('Nationality'),
    'Ethnicity' => set_value('Ethnicity'),
    'ClientNotes' => set_value('ClientNotes')
);

I have also tried 'CreateDate' => set_value(date('Y-m-d H:i:s')) which also does not produce an error but no value is entered into the database for this column
 
Associate
OP
Joined
19 Jul 2006
Posts
1,847
Cheers Poolybit,

After going round all the things i could think of i tried
'CreateDate' => (date('Y-m-d H:i:s')),

NO SET_VALUE and it worked. I dont know why that should make a difference
 
Associate
OP
Joined
19 Jul 2006
Posts
1,847
Yep codeIgniter,

The formdata array collects all the form data :) and then is passed to an insert query, Poolybit's solution does work.
But would the ideal solution be to split the inset date from that array and into another function for example?
 
Back
Top Bottom