PHP: Loop through dates (from date to date) with strtotime() function

This is very easy way loop through dates (from date to date) with PHP strtotime() function. This example only echo dates, but of course this model can be used more complicated situations.

Note: All different PHP strtotime() function syntaxes can be used.

Share this post


  1. I used to use this method myself, but then I realised that when the date crosses between daylight savings time and standard time, there’s at least one extra hour in the day. In the UK, for example, adding 86400 seconds to 2014-10-25 returns 2014-10-25 23:00:00.

  2. If you want to use a for loop instead, try this:

  3. I think now it’s better to use DatePeriod class

  4. thanks a lot.this example saved me.keep up the good work guys :)

  5. please help me get, this loop
    star date column I end date column
    2015-02-01 I 2015-02-05
    2015-02-06 I 2015-02-09

    i need to echo these between all days like..
    2015-02-01, 2015-02-02, 2015-02-03, 2015-02-04, 2015-02-05, 2015-02-06, 2015-02-07, 2015-02-08, 2015-02-09

  6. Hi JK,

    Nice guide thanks for sharing this.

  7. Thank’s, Good Article :D
    It’s very helpfull.


Submit a Comment

Your email address will not be published. Required fields are marked *