Hello everyone,
I am new to codeigniter I want to insert current date in mysql and i am trying to get the current date using now function.But its not working out for me.Can any one help me.Thanks in advance.
This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.
The active forums are here.
October 13, 2011 10:53am
Subscribe [2]#1 / Oct 13, 2011 10:53am
Hello everyone,
I am new to codeigniter I want to insert current date in mysql and i am trying to get the current date using now function.But its not working out for me.Can any one help me.Thanks in advance.
#2 / Oct 13, 2011 11:41am
Try this:
echo 'Date/time ==> ' .date('d:m:Y; H:m:s', time()) ?>
http://ellislab.com/codeigniter/user-guide/helpers/date_helper.html
#3 / Oct 13, 2011 12:15pm
thanks John
Using your code I can print the date,but when I m trying to take it in a variable and try to insert it in the database 0000-00-00 this value is inserted.
this is the code i have written in the controller:
$datetime = date(‘dⓂ️Y; HⓂ️s’, time());
$form_data = array(
‘Username’ => $username,
‘Headline’ => set_value(‘Headline’),
‘Description’ => set_value(‘Description’),
‘Pricing’ => set_value(‘Pricing’),
‘MBDescription’ => set_value(‘MBDescription’),
‘Information’ => set_value(‘Information’),
‘status’ => ‘pending’,
‘DoP’ => $datetime
);
// run insert model to write data to db
$this->books_model->SaveForm($form_data);
#4 / Oct 13, 2011 1:01pm
What is $this->books_model->Dop type? It looks like a date, datetime or a timestamp.
$datetime requires converting to the same field type.
When saving a record I prefer using a default TIME_STAMP. This eliminates having to get the date, convert it to the correct field type and then store the result. Let MySQL do all the work.
edit: added TIME_STAMP details.
#5 / Oct 13, 2011 1:17pm
Thanks Jhon its done
#6 / Oct 13, 2011 1:21pm
‘pleased I was able to help.
PHP dates and MySQL dates give a lot of options. I find TIME_STAMP to suit my needs and is quite easy to convert.