Yii Framework Forum: DB Attribute with TIMESTAMP - Not possible to save timestamp - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

DB Attribute with TIMESTAMP - Not possible to save timestamp Rate Topic: -----

#1 User is offline   Andreas123 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 89
  • Joined: 11-March 11
  • Location:$3RdF

Posted 29 March 2011 - 12:58 PM

Hey guys,
I have an attribute called "date" in my DB with the datatype "TIMESTAMP"
When executing the following code in my model the following data is saved in the DB:
0000-00-00 00:00:00
(instead of the timestamp..)

Model Code:
	protected function beforeValidate()
	{		
		$this->date = time(); 

		return parent::beforeValidate();
	}

0

#2 User is offline   phtamas 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 529
  • Joined: 26-February 11
  • Location:Mezőtúr, Hungary

Posted 29 March 2011 - 01:34 PM

Your DBMS doesn't accept an integer value for a timestamp column. It needs to be converted to a properly formatted string:

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


0

#3 User is offline   Andreas123 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 89
  • Joined: 11-March 11
  • Location:$3RdF

Posted 29 March 2011 - 03:06 PM

View Postphtamas, on 29 March 2011 - 01:34 PM, said:

Your DBMS doesn't accept an integer value for a timestamp column. It needs to be converted to a properly formatted string:

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




yep.. THX that makes sense
0

#4 User is offline   zainiafzan 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 10-April 11

Posted 24 November 2011 - 05:35 PM

Thanks..help me too.. :lol:
0

#5 User is offline   Istrak 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 23-January 13
  • Location:Mexico

Posted 11 March 2013 - 02:57 PM

Don't Work for me I use this code

$model->fechora=date('Y-m-j h:i');


And show this error
CDbCommand failed to execute the SQL statement: SQLSTATE[22007]: Invalid datetime format:
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users