![]() |
I am not able to insert NOW() - 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: I am not able to insert NOW() (/showthread.php?tid=26035) |
I am not able to insert NOW() - El Forum - 01-04-2010 [eluser]shinokada[/eluser] I have the following model. Code: $data = array ( It does not give any error, but NOW() is inserted as 0000-00-00 00:00:00. order_date has the type of datetime. Could anyone tell me what I am doing wrong please? I am not able to insert NOW() - El Forum - 01-04-2010 [eluser]Craig A Rodway[/eluser] ActiveRecord escapes things like that. Either use PHP to set the date: Code: 'order_date' => date('Y-m-d H:i:s'), Or use the set() function and tell CI not to escape it (but remove the line from your $data array first): Code: $this->db->set('order_date', 'NOW()', FALSE); I am not able to insert NOW() - El Forum - 01-04-2010 [eluser]shinokada[/eluser] Thanks for your help. :-) The following works. Code: $data = array ( I am not able to insert NOW() - El Forum - 01-04-2010 [eluser]shinokada[/eluser] Now how can I pull out only date from DATETIME? SELECT DATE('order_date') FROM ('omc_orders') Am I correct? I am not able to insert NOW() - El Forum - 01-04-2010 [eluser]davidbehler[/eluser] For MySQL have a look at the DATE_FORMAT function. I am not able to insert NOW() - El Forum - 01-04-2010 [eluser]Craig A Rodway[/eluser] If you need to display it in multiple formats within your app, you can do it this way with a regular select: Code: SELECT order_date FROM omc_orders And just use the PHP date() and strtotime() functions to format and show it, like this: Code: echo date('Y-m-d, H:i', strtotime($row->order_date)); (The first parameter can obviously be any valid date format that is accepted by the date() function) |