Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Want to show date counter

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?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

$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>";
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading