× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

PHP next second friday relative to current date

Jérôme Gamez
Apr 29, 2015
<p>The first solution that came into my mind was this:</p> <pre><code>$dt = new DateTime(); $dt-&gt;modify('next friday'); // Next friday from now $dt-&gt;modify('next friday'); // Next friday from next friday echo $dt-&gt;format('Y-m-d'); </code></pre> <p>or, as the function hinted at in your post:</p> <pre><code>function next_dispatch_date($timestamp){ $dt = new DateTime(); $dt-&gt;setTimestamp($timestamp); $dt-&gt;modify('next friday'); $dt-&gt;modify('next friday'); return $dt-&gt;format('Y-m-d'); } echo "Next dispatch on ".next_dispatch_date(time()); </code></pre> <p>Please note, compared to your original post, that I used <code>time()</code> and not <code>date()</code>, which is used for formatting timestamps.</p> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/29755481/PHP%20next%20second%20friday%20relative%20to%20current%20date/29755633">Stack Overflow</a>.</p>

Get New Tutorials Delivered to Your Inbox

New tutorials will be sent to your Inbox once a week.

comments powered by Disqus