B
B
Boris Yakushev2016-09-16 16:21:27
Yii
Boris Yakushev, 2016-09-16 16:21:27

Adding your date to timestamp yii2?

Good afternoon.
At the moment, the current date is written in buy_at, stop_at:

return [
    'timestamp' => [
        'class' => TimestampBehavior::class,
        'attributes' => [
            ActiveRecord::EVENT_BEFORE_INSERT => [
                'buy_at', 'stop_at',
            ],
        ],
        'value' => new Expression('NOW()'),
    ],
];

But, how to do something in buy_at to write the current date, and in stop_at the current date + 30 days?
Thanks everyone for the advice.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2016-09-16
@za4me

if you need to generate your own date for each field, you need to connect the behavior twice, for example:

return [
    'timestamp_buy_at' => [
        'class' => TimestampBehavior::class,
        'attributes' => [
            ActiveRecord::EVENT_BEFORE_INSERT => [
                'buy_at',
            ],
        ],
        'value' => new Expression('NOW()'),
    ],
    'timestamp_stop_at' => [
        'class' => TimestampBehavior::class,
        'attributes' => [
            ActiveRecord::EVENT_BEFORE_INSERT => [
                'stop_at',
            ],
        ],
        'value' => new Expression('NOW() + INTERVAL 30 DAY'),
    ],
];

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question