samedi 15 juin 2019

How to change badge color depending date_diff results?

i have a table with three dates, and i use date_diff to find some results, and its working. This results are displayed inside a bootstrap badge, but im trying that depending the result the badge change color.

<?php
$date1 = date_create($lines3x['date_open']);
$date2 = date_create($lines3x['date_close']);
$date3 = date_create($lines3x['date_finish']);
//difference between two dates
$diff = date_diff($date1,$date2);
$diff2 = date_diff($date2,$date3);
?>

 <td><span class="badge badge-info"><? echo $diff2->format("%a");?></span></td>

For example if the $diff2 result between 10 and 20 the badge should be like this:

<span class="badge badge-warning">`

ìf bigger than 20 the badge should be:

<span class="badge badge-danger">`

Any ideas to accomplish this?

Aucun commentaire:

Enregistrer un commentaire