ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Get current date

October 13, 2011 10:53am

Subscribe [2]
  • #1 / Oct 13, 2011 10:53am

    sameer

    2 posts

    Hello everyone,
          I am new to codeigniter I want to insert current date in mysql and i am trying to get the current date using now function.But its not working out for me.Can any one help me.Thanks in advance.

  • #2 / Oct 13, 2011 11:41am

    John_Betong_002

    407 posts

    Try this:

    echo   'Date/time ==> ' .date('d:m:Y; H:m:s', time()) ?>

     

    http://ellislab.com/codeigniter/user-guide/helpers/date_helper.html

     

    http://php.net/manual/en/function.date.php
     

  • #3 / Oct 13, 2011 12:15pm

    sameer

    2 posts

    thanks John
    Using your code I can print the date,but when I m trying to take it in a variable and try to insert it in the database 0000-00-00 this value is inserted.
    this is the code i have written in the controller:

    $datetime = date(‘dⓂ️Y; HⓂ️s’, time());
                        $form_data = array(
        ‘Username’ => $username,
            ‘Headline’ => set_value(‘Headline’),
            ‘Description’ => set_value(‘Description’),
            ‘Pricing’ => set_value(‘Pricing’),
            ‘MBDescription’ => set_value(‘MBDescription’),
            ‘Information’ => set_value(‘Information’),
        ‘status’ => ‘pending’,
        ‘DoP’ => $datetime
        );
       
      // run insert model to write data to db
                    $this->books_model->SaveForm($form_data);

  • #4 / Oct 13, 2011 1:01pm

    John_Betong_002

    407 posts

    What is $this->books_model->Dop type? It looks like a date, datetime or a timestamp.

    $datetime requires converting to the same field type.

    When saving a record I prefer using a default TIME_STAMP. This eliminates having to get the date, convert it to the correct field type and then store the result. Let MySQL do all the work.

     
    edit: added TIME_STAMP details.

  • #5 / Oct 13, 2011 1:17pm

    sameer

    2 posts

    Thanks Jhon its done

  • #6 / Oct 13, 2011 1:21pm

    John_Betong_002

    407 posts

    ‘pleased I was able to help.

    PHP dates and MySQL dates give a lot of options. I find TIME_STAMP to suit my needs and is quite easy to convert.
     

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases