Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Easiest way would be to get a timestamp that corresponds to today, using the <a href="http://www.php.net/time" rel="nofollow noreferrer"><code>time()</code></a> function ; and 7 times remove 1 day to that timestamp, each echoing the date that corresponds to that timestamp :</p> <pre><code>$timestamp = time(); for ($i = 0 ; $i &lt; 7 ; $i++) { echo date('Y-m-d', $timestamp) . '&lt;br /&gt;'; $timestamp -= 24 * 3600; } </code></pre> <p>Which will get you this output :</p> <pre><code>2010-02-25 2010-02-24 2010-02-23 2010-02-22 2010-02-21 2010-02-20 2010-02-19 </code></pre> <p>Because a timestamp only represents the number of seconds since <code>1970-01-01</code>, substracting one day to a timestamp means substracting <code>24*3600</code> seconds.</p> <hr> <p><strong>Edit after the comments :</strong> </p> <p>For month and weeks changes, this will still work : one day is still 24*3600 seconds.</p> <p>For instance, if you test using this line instead of the first one I posted in my first example :</p> <pre><code>$timestamp = strtotime('2010-02-03'); </code></pre> <p>You'll get this output :</p> <pre><code>2010-02-03 2010-02-02 2010-02-01 2010-01-31 2010-01-30 2010-01-29 2010-01-28 </code></pre> <p>It changed of month fine.</p> <p><br> For leap years, if I test using this :</p> <pre><code>$timestamp = strtotime('2008-03-03'); </code></pre> <p>I get :</p> <pre><code>2008-03-03 2008-03-02 2008-03-01 2008-02-29 2008-02-28 2008-02-27 2008-02-26 </code></pre> <p>Which looks fine, as there were 29 days in february 2008.</p> <p>And if I test with :</p> <pre><code>$timestamp = strtotime('2009-03-03'); </code></pre> <p>I get :</p> <pre><code>2009-03-03 2009-03-02 2009-03-01 2009-02-28 2009-02-27 2009-02-26 2009-02-25 </code></pre> <p>Which looks fine too.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload