Rate this post

 

Mysql provides the automatic initialization and updating to the current date and time for TIMESTAMP and DATETIME types. When you insert or update a row into data table, these fields will be updated automatically by the current time. So you do not need to set the value of these fields in your PHP code.

Magento 2 has supported us to create auto update time attributes. We can write the script in InstallSchema file.

app/code/[NameSpace]/[ModuleName]/Setup/InstallSchema.php

create auto update time attributes
create auto update time attributes

In this example I’ll add two columns to my table: created_at and updated_at. The created_time will be initialed when we add a new row into data table. The updated_time will be changed every time we update a row in data table.

After run php bin/magento setup:upgrade in console, you will see these fields has been created in Mysql.

create auto update time attributes
create auto update time attributes

Check here for Magento extensions and Magento 2 extensions now !

Your Magento website needs a powerful Magento ERP for stock control.

DON'T MISS THE CHANCE!

magento erp

How to Show Listing Items ( Grid ) on The Form in Magento 2
How to Reload Ui Component Grid Table with Js