How To Get Numbers of Days Present Between Two Dates In PHP

admin_img Posted By Bajarangi soft , Posted On 27-11-2020

using php we can get numbers of days which is present between two dates.So today we implement code to get days presents between two days using php

How To Get Numbers of Days Present Between Two Dates In PHP

Complete Code For Numbers of Days Present Between Two Dates In PHP.

<!DOCTYPE html>
<html>
<head>
    <title>How To Get Numbers of Days Present Between Two Dates In PHP</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet">
</head>
<style>
    body {
        background: black;
    }
</style>
<body>
<body>
<div class="container">
    <br/><br/>
    <div class="text-center">
        <h1 id="color" style="color: white;"> Get Numbers of Days Present Between Two Dates In PHP</h1>
    </div>

    <div class="well">
        <form action="" method="post" enctype="multipart/form-data">
            <label>Enter From Date</label><br>
            <input type="date" name="date1" value=""><br><br>
            <label>Enter To Date</label><br>
            <input type="date" name="date2" value=""><br><br>
            <input type="submit" value="submit" class="btn btn-success" name="submit">
        </form>
        <?php
        if (isset($_POST['submit'])) {

            //get the number entered
            $date1 = $_POST['date1'];
            $date2 = $_POST['date2'];
            // Calculating the difference in timestamps
            $diff = strtotime($date2) - strtotime($date1);

            // 1 day = 24 hours
            // 24 * 60 * 60 = 86400 seconds
            $total= abs(round($diff / 86400));
            echo "Different Between Two Dates ".$total." days";
        }
        ?>
    </div>
</div>
</body>
</html>

Related Post