Home > database >  Want to show date counter
Want to show date counter

Time:05-25

I want to make date counter in following codes. the format must be

today's date - previous date

. I tried to add but I think the format is wrong. Can you guys please check? Screenshot is added down below.

if (mysqli_num_rows($result) > 0) {
                $row = mysqli_fetch_array($result);
                $curr_dt = DateTime::createFromFormat("Y-m-d H:i:s", date("Y-m-d") . " 00:00:00");

                $row_dt = DateTime::createFromFormat("Y-m-d H:i:s", $row["dt_corr"]);

                $color = $row_dt < $curr_dt ? 'red' : 'lime';
        
                $date = "<br><font  style='color: $color; font-size:12px'>".date("d/m/Y",strtotime($row["dt_corr"]))."</font >";
                
                $currentdate = date('Y-m-d H:i:s');
                $after1yrdate =  date("Y-m-d H:i:s", strtotime(" 1 year", strtotime($row["dt_corr"])));

                $diff = (strtotime($after1yrdate) - strtotime($currentdate)) / (60 * 60 * 24);

                echo "<p style='color:red'>The difference is ".round($diff)." Days</p>";

            }
            /*if (mysqli_num_rows($result) > 0) {
                $row = mysqli_fetch_array($result);
                $date = "<br><font size=\"2px\" color=\"green\">".$row["dt_corr"]."</font>";
                
                //echo $date.'<br>';
            }*/
            else{
                $date = "";
            }

It has to be deduct like today's date - 16/10/2021

CodePudding user response:

$currentdate = date('Y-m-d H:i:s');
                $previousdate =  date("Y-m-d H:i:s", strtotime($row["dt_corr"]));

                $diff = (strtotime($currentdate)-strtotime($previousdate)) / (60 * 60 * 24);

                echo "<p style='color: $color; font-size:12px'>".round($diff)." days </p>";
  • Related