-2

I am trying to work out how to highlight dates dragged from a MySQL db as per the following:

  • If database date is today then echo in green
  • If database date is tomorrow then echo in orange
  • If database date is the day after tomorrow then echo in red

Does anyone have any ideas how I can do this?

I have tried the following but for some reason dates way in to the future are displayed in red. I'm not sure if the code I am using is the best way to achieve this.

$date=date("d/m/Y", strtotime($rows['collect_date']));

if ($date==date(("d/m/Y"), strtotime('+1 days')) && $rows['status']=='4')
{
echo "<span class='label label-danger1'>".$date."</span>";
}
elseif ($date==date(("d/m/Y")) && $rows['status']=='4')
{
echo "<span class='label label-danger'>".$date."</span>";
}
elseif ($date==date(("d/m/Y"), strtotime('+2 days')) && $rows['status']=='4')
{
echo "<span class='label label-warning'>".$date."</span>";
}
elseif (strtotime($date) < strtotime('1 day ago') && $rows['status']=='4')
{
echo "<span class='label label-danger'>".$date."</span>";
}
else 
{
echo $date;
}

Custom CSS:

.label-danger1{
  background-color: #FF6666;
}

Many thanks,

John

John Higgins
  • 857
  • 12
  • 25

1 Answers1

1

Try this code

if($date  == date('d/m/Y'))
echo '<span  style=" background-color: green">its today';
else
if($date  == date('d/m/Y',strtotime("+1 days")))
echo '<span  style=" background-color: orange">it will be yesterday<span>';

else
echo '<span  style=" background-color: red">it will be '.$date.'<span>';

Check this link also php mysql today, yesterday and date from database

Community
  • 1
  • 1
rack_nilesh
  • 553
  • 5
  • 18