Welcome Guest, Not a member yet? Register   Sign In
Insert auto date
#5

(This post was last modified: 06-22-2016, 01:01 AM by pravins.)

(06-22-2016, 12:43 AM)davy_yg Wrote:
(06-21-2016, 09:46 PM)pravins Wrote: If you are explicitly want to add date in table then you can use below code


PHP Code:
$this->db->set('content_date''NOW()'FALSE);
 
   or 
$data
['content_date'] = date('Y-m-d H:i:s'); 

and if you want to add date automatically when article is inserted, then you need to set default value of date field as CURRENT_TIMESTAMP and its data type should be timestamp

hope this will help you


This is good.  But what if I only want to type the date without timestamp.  Can anyone help me? 


Pages_model.php



PHP Code:
public function insert_pages()
        {
                        
                $data 
= array(
                    'pages_name' => $this->input->post('pages_name'),
                    'create_date'  => date('Y-m-d'),
                    'pages_order' => $this->input->post('pages_order'),
                    'pages_content' => $this->input->post('pages_content')                
                
);
            
                
return $this->db->insert('pages'$data);
        


and I get this new error message:

Thank you for filling the information. It has been successful.

Pages Name: Home
Create Date:
A PHP Error was encountered
Severity: Notice
Message: Undefined index: create_date
Filename: views/submitpages.php
Line Number: 45
Backtrace:
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyProfileCI\application\views\submitpages.php
Line: 45
Function: _error_handler
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyProfileCI\application\controllers\Cpages.php
Line: 107
Function: view
File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\CompanyProfileCI\index.php
Line: 315
Function: require_once

Order: 2



you can use MySQL DATE(NOW()) function instead of NOW() in

PHP Code:
$this->db->set('content_date''DATE(NOW())'FALSE); 

also your field name is 'content_date' or 'create_date'
Reply


Messages In This Thread
Insert auto date - by davy_yg - 06-21-2016, 06:17 PM
RE: Insert auto date - by pravins - 06-21-2016, 09:46 PM
RE: Insert auto date - by davy_yg - 06-22-2016, 12:43 AM
RE: Insert auto date - by pravins - 06-22-2016, 12:53 AM
RE: Insert auto date - by InsiteFX - 06-22-2016, 12:07 AM



Theme © iAndrew 2016 - Forum software by © MyBB