2

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(
            $setup->getTable('magento_customerbalance_history'),
            'created_at',
            [
                '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?

1 Answer 1

3

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 and acknowledge you have read our privacy policy.

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