0

I have a field that I am trying to have the text show RED if the date matches today. I also have to adjust for the server time being different than local time.

Here is what I have tried, which does not work and produces errors

global $data;
 $str = "<font color=";
if ($value=="date("m/d/Y")")
 $str.="red";
 $str.=">".$value."</b></font>";
 $value=$str;

global $data;
 $str = "<font color=";
if ($value==date('Y-m-d', strtotime("-8 hour"))
 $str.="red";
 $str.=">".$value."</b></font>";
 $value=$str;
5
  • You're missing <b> to match </b>
    – Barmar
    Commented Aug 21, 2014 at 23:57
  • Use date_default_timezone_set() to adjust for different timezones.
    – Barmar
    Commented Aug 21, 2014 at 23:58
  • Use CSS rather than <font> and <b>.
    – Barmar
    Commented Aug 21, 2014 at 23:58
  • What errors are you getting?
    – Barmar
    Commented Aug 21, 2014 at 23:59
  • Your quoting is wrong on the if ($value=="date("m/d/Y")") line, that's probably why you're getting errors.
    – Barmar
    Commented Aug 22, 2014 at 0:00

1 Answer 1

0

I am trying to understand your question but if you mean you what to highlight the current date according to your server time minus 8 hours below could be your code.

<?php
 $dt_value = '08/22/2014';//sample date
 $today_minus8hrs = date('m/d/Y',strtotime('-8 hours'));

 if($dt_value == $today_minus8hrs){
   $color = 'red';
 }
?>

<p><font color="<?php echo $color?>" > <?php echo $dt_value?>  </font></p>
2
  • I am trying to change the font color to red if the date in the field is equal to today. If the date is not today, then no change is needed
    – Robert
    Commented Aug 23, 2014 at 1:57
  • if you are referring to the server current local time change this line From: $today_minus8hrs = date('m/d/Y',strtotime('-8 hours')); To: $today = date('m/d/Y',time()); change the variable $today_minus8hrs to $today
    – ociugi
    Commented Aug 26, 2014 at 0:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.