Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code igniter date helper now() not working

code igniter date helper in not working for me. I initialized the date helper and while inserting in database. I see that field with timestamp are returning 0000-00-00 . Code for insertion is:

function add_todo($list)
{
 date_default_timezone_set("Asia/kathmandu");
    $date = now();
     $data = array(
        'list' => $list,
        'dates'=> now()
    );

    $insert = $this->db->insert('todo', $data);
 }  

I cannot get is working. What is the problem here.

like image 459
user254153 Avatar asked Jan 24 '26 07:01

user254153


1 Answers

Id imagine its not working because you don't have the correct configuration.

This is from the codeigniter wiki for the now() function:

Returns the current time as a Unix timestamp, referenced either to your server's local time or GMT, based on the "time reference" setting in your config file. If you do not intend to set your master time reference to GMT (which you'll typically do if you run a site that lets each user set their own timezone settings) there is no benefit to using this function over PHP's time() function.

try using this

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

This would be revised code but I'm not at a machine were i can test it. However, this should work..

function add_todo($list)
{
    date_default_timezone_set("Asia/kathmandu");
    $datetime = date('Y-m-d H:i:s'); 
    $data = array(
          'list' => $list,
          'dates'=> $datetime
   );

    $insert = $this->db->insert('todo', $data);
}  
like image 174
Robbie Avatar answered Jan 25 '26 20:01

Robbie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!