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

20 Comments

  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.

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

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

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

    Reply

Submit a Comment

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">