CodeIgniter Forums
save current date and time in mysql with codeigniter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: save current date and time in mysql with codeigniter (/showthread.php?tid=21727)



save current date and time in mysql with codeigniter - El Forum - 08-18-2009

[eluser]ranjitbd[/eluser]
function feedbackSave()
{
$data=array();

$data['name'] = $this->input->post('lname', true);
$data['email'] = $this->input->post('email', true);
$data['comments'] = $this->input->post('comments', true);

1. $date = date('Y-m-d');
2. $time = date('h:iConfused');
3. $dateTime = $date." ".$time;

4. $data['date'] = $dateTime;

$this->load->model($this->config->item('generalModel'), 'save_feedback',TRUE);
$this->save_feedback->feedbackSave($data);

$_SESSION['feedback'] = 'Feedback send successfully';
$this->feedback();
}

hi,
i have saved current date and time in mysql using line no 1,2,3,4. this is the way i used in php raw coding.
is there any convenient way or builtin function for doing this using codeigniter..
sorry for my poor english...
thanks in advance


save current date and time in mysql with codeigniter - El Forum - 08-18-2009

[eluser]Johan André[/eluser]
Sure... But why not:

Code:
$datetime = date('Y-m-d H:i:s');

Or make the database create a timestamp on create with todays date/time?

It also seems that you are setting a session at the end?
Is that for flash-messages?

Use the session-class instead:

Code:
$this->session->set_flashdata('feedback', 'Message');

...and you don't need to bother about clearing it manually afterwards.