Home > front end >  What's the easiest way to change a text's color based on today's date?
What's the easiest way to change a text's color based on today's date?

Time:11-22

For example: If given date is less than today's date it has to show red, if given date is greater than today's date it has to show green.

CodePudding user response:

 <?php
            function getTheDay($date)
            {
                $curr_date=strtotime(date("Y-m-d H:i:s"));
                $the_date=strtotime($date);
                $diff=floor(($curr_date-$the_date)/(60*60*24));
                switch($diff)
                {
                    case 0:
                        return '<p style="color:green">Today</p>';
                        break;
                    case 1:
                        return '<p style="color:red">Yestarday</p>';
                        break;
                    default:
                        return $diff.' Days ago';
                }
            }
            
            echo getTheDay('2021-11-21');

        ?>
  • Related