0

How to echo all dates between two dates?

for example: From the date of 2020/07/29 to the date of 2020/08/02

I want to print the results

2020/07/29 
2020/07/30
2020/07/31
2020/08/01
2020/08/02

The following code prints only to 2020/07/31

if(isset($_POST['submit'])){
    $from_date= $_POST['from_date'];
    $to_date  = $_POST['to_date'];

    for($from_date = $from_date ; strtotime("+$from_date Day") <=  $to_date; $from_date++){
        echo $from_date . "<br>";
    }
}

Result:

2020/07/29
2020/07/30
2020/07/31

HTML FORM

<form action="" method="post">
    <input type="date" name="from_date">
    <input type="date" name="to_date" >
    <input name="submit" type="submit" value="submit">
</form>

Thanks

Ynjxsjmh
  • 28,441
  • 6
  • 34
  • 52
hattamyDS
  • 1
  • 1
  • Does this answer your question? [I have 2 dates in PHP, how can I run a foreach loop to go through all of those days?](https://stackoverflow.com/questions/3207749/i-have-2-dates-in-php-how-can-i-run-a-foreach-loop-to-go-through-all-of-those-d) – Ynjxsjmh Aug 04 '20 at 04:49
  • Yes, this is required Thank you very much – hattamyDS Aug 05 '20 at 07:20

0 Answers0