![]() |
how to insert a current date into a database - 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: how to insert a current date into a database (/showthread.php?tid=22629) |
how to insert a current date into a database - El Forum - 09-15-2009 [eluser]Unknown[/eluser] hi . i want to insert the current date and time into the database . In database i was created a table named userdtails in that i created one field named ts_created of type datetime . In this field i have to insert date and time for the detail about the user . date and time in format of yyyy/mm/dd hrs/minutes/seconds please anyone help me how to insert a current date into a database - El Forum - 09-16-2009 [eluser]Madmartigan1[/eluser] www.php.net/date how to insert a current date into a database - El Forum - 09-16-2009 [eluser]m4d3 Gun[/eluser] wish this can help u.... //front controller <? function save(){ if($this->input->post('submit')){ $now = date('Y-m-d H:i ![]() $data = array( 'name'=>$this->input->post('name'), 'address'=>$this->input->post('address'), 'ts_created'=>$now ); $this->db->insert('userdtails',$data) redirect('front/index','refresh'); ?> //than in the view <? <?=form_open('front/save');?> <table width="522"> <tr> <td width="138">Name</td> <td width="372"> <input name="name" size="30" type="text" /></td> </tr> <tr> <td width="138">Address</td> <td width="372"> <input name="address" size="30" type="text" /></td> </tr> <p><input name="submit" type="submit" value="Save" /></p> </table> </form> ?> how to insert a current date into a database - El Forum - 09-16-2009 [eluser]n0xie[/eluser] [quote author="sramkrish" date="1253098235"]hi . i want to insert the current date and time into the database . In database i was created a table named userdtails in that i created one field named ts_created of type datetime . In this field i have to insert date and time for the detail about the user . date and time in format of yyyy/mm/dd hrs/minutes/seconds please anyone help me[/quote] Most databases have an option to fill the current timestamp in a field when a new record is inserted. Presuming you use MySQL take a look here. how to insert a current date into a database - El Forum - 09-16-2009 [eluser]Unknown[/eluser] thank you how to insert a current date into a database - El Forum - 09-16-2009 [eluser]renownedmedia[/eluser] Code: INSERT INTO table SET datecol = NOW() how to insert a current date into a database - El Forum - 09-16-2009 [eluser]laytone[/eluser] [quote author="m4d3" date="1253101145"]wish this can help u.... //front controller <? function save(){ if($this->input->post('submit')){ $now = date('Y-m-d H:i ![]() $data = array( 'name'=>$this->input->post('name'), 'address'=>$this->input->post('address'), 'ts_created'=>$now ); $this->db->insert('userdtails',$data) redirect('front/index','refresh'); ?> //than in the view <? <?=form_open('front/save');?> <table width="522"> <tr> <td width="138">Name</td> <td width="372"> <input name="name" size="30" type="text" /></td> </tr> <tr> <td width="138">Address</td> <td width="372"> <input name="address" size="30" type="text" /></td> </tr> <p><input name="submit" type="submit" value="Save" /></p> </table> </form> ?>[/quote] Using this method make sure that your database field is a DateTime and not just a date field. |