This post will find all the dates between the two dates in PHP. We will create two variables start date and end date in DD-MM-YYYY format and find all the dates between the two dates. We can select from the date and end date through the date picker and after submitting the form we can see all the dates between these two dates. In this example, we will use theĀ strtotime() function to find all dates between two dates.
<?php
if(isset($_POST[‘submit’])){
$allDates = [];
$fromdate = strtotime($_POST[‘fromdate’]);
$todate = strtotime($_POST[‘todate’]);
for ($currentDate = $fromdate; $fromdate <= $todate; $fromdate += (86400)) {
$date = date(‘Y-m-d’, $fromdate);
$allDates[] = $date;
}
}
?>
<html>
<head>
<title>Find All Dates Between Two Date In PHP</title>
<link rel=”stylesheet” href=”https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css” />
</head>
<body>
<h3 class=”text-success” align=”center”>Find All Dates Between Two Date In PHP</h3><br>
<div class=”container”>
<div class=”panel-group”>
<div class=”panel panel-primary”>
<div class=”panel-heading”>Find All Dates Between Two Date In PHP</div>
<form class=”form-horizontal” method=”post”>
<div class=”panel-body”>
<div class=”form-group”>
<label class=”control-label col-sm-2″ for=”title”>From Date:</label>
<div class=”col-sm-2″>
<input type=”date” class=”form-control” id=”fromdate” name=”fromdate” required>
</div>
<label class=”control-label col-sm-2″ for=”title”>To Date:</label>
<div class=”col-sm-2″>
<input type=”date” class=”form-control” id=”todate” name=”todate” required>
</div>
<div class=”col-sm-2″>
<input type=”submit” class=”btn btn-primary” value=”submit” name=”submit”>
</div>
</div>
<?php if(!empty($allDates)){ ?>
<ul class=”list-group”>
<?php foreach ($allDates as $date) { ?>
<li class=”list-group-item”>Date : <?= date(“d-m-Y”, strtotime($date))?></li>
<?php } ?>
</ul>
<?php } ?>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
Find All Date Between Two Dates In JavaScript.
Server Side Data Table Implementation In Laravel.
The post Find All Date Between Two Dates In PHP. appeared first on PHPFOREVER.