0

I want to change row color as per MySQL query where expiry date is greater than current date and less than within month.

'rowOptions'=>function($model) {
  if($model['expirydate'] >= '2018-08-10') {
    return ['class' => 'danger'];
  }
},

How can I use below condition in rowOption to highlight upcoming expiry domain row--

$domains=Domains::find()
->Where('expirydate BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 1 MONTH)')
->andWhere(['or',['status'=> 'Active'],['status'=> 'Pending Transfer']])
->orderBy(['expirydate' => SORT_ASC])
->all();   

1 Answer 1

1

You need to do it in PHP, and you can use the \DateTime() class for comparing the dates between the range

[
    'rowOptions' => function ($model, $key, $index, $grid) {
        $db_date = new DateTime($model->expirydate);

        $range_start = new DateTime();
        $range_end = new DateTime();
        $range_end->add(new DateInterval('P1M'));

        //if between range 
        if ($db_date >= $range_start && $db_date <= $range_end) {
            return[
                'class' => 'green'
            ];
        } else {
            return [
                'class' => 'red'
            ];
        }
    }
]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.