-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

6
  • From the database, are they UNIX timestamps? Commented Jul 14, 2014 at 13:12
  • Show us what you've tried so far an explain what's not working. Commented Jul 14, 2014 at 13:13
  • @PatrickQ I have edited my original post with the code I am using currently but for some reason this shows up dates well into the future as red. Thanks Commented Jul 14, 2014 at 13:17
  • It would probably help to see your CSS as well. It's possible that that's where the problem is. Commented Jul 14, 2014 at 13:24
  • @PatrickQ I have amended the post to include the only bit of custom CSS I have included. The rest is using the Twitter Bootstrap framework. Commented Jul 14, 2014 at 13:32

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.