I have custom table and attachment is a structure of the database.
I Save data with
$post_data['created_date'] = now();
$model = Mage::getModel("rapnet/rapnet")->addData($post_data)->save();
Created date is now() and updated date is "CURRENT_TIMESTAMP". So why both are different on my localhost? How can we solve this to keep both same while creating a new record?
Best Answer
I had this issue early (it because your database set to one locale, but server to another).
So, here is a solution.
First: don't use
now()
function, useMage::getModel('core/date')->timestamp();
in Magento.Second: don't use
CURRENT_TIMESTAMP
as a default value for your magento database. Set bothcreated_at
andupdated_at
fields toDATETIME
type.Just use this upgrade script:
or this (if you already have these columns):
Third: in your model add function
_beforeSave()
(and you shouldn't set date manually anymore) and in that function make next logic: if it just created setcreated_at
to current time using function above, and setupdated_at
to current time.It looks like:
Fourth: also it is good practice in magento to call your columns
created_at
andupdated_at
.Hope it will be helpful for you :)