I am not able to insert NOW() |
[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?
[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);
[eluser]shinokada[/eluser]
Thanks for your help. :-) The following works. Code: $data = array (
[eluser]shinokada[/eluser]
Now how can I pull out only date from DATETIME? SELECT DATE('order_date') FROM ('omc_orders') Am I correct?
[eluser]davidbehler[/eluser]
For MySQL have a look at the DATE_FORMAT function.
[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) |
Welcome Guest, Not a member yet? Register Sign In |