I want to set expiry date for let say store credit, I have created custom column by installschema in table as:

        $table = $setup->getConnection()->addColumn(
                'type' => Table::TYPE_TIMESTAMP,
                'nullable' => 'false',
                'default' => Table::TIMESTAMP_INIT,
                'comment' => 'Creation Date'

I want to create a column 'expiry date', formula could be:

$expiry_date = $created_at + $one_month;

How to do this manipulation and save value in Table?


You can use following code to get next month.

$nextmonth = mktime(0, 0, 0, date("m")+1, date("d"),   date("Y"));

/** @var \Magento\Framework\Stdlib\DateTime\DateTime $dateTime */
$dateTime = $obj->create(\Magento\Framework\Stdlib\DateTime\DateTime::class);

echo $dateTime->gmtDate(); // 2019-07-18 09:35:19
echo "<br>";
echo $dateTime->gmtDate(null, $nextmonth); // 2019-08-18 00:00:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.