"rf" <ry***@twcny.rr.com> kirjoitti
viestissä:11**********************@o13g2000cwo.goo glegroups.com...
Hey I need to be able to get the dates from last wednesday to the past
tuesday on thursday or friday every week. How would I do that?
For example:
m t W TH F
M T w th f
I would need the dates of the CAPITAL W and T when I run the script
from the last th or f
So if today is 2006-1-19 I would need 2006-1-11 and 2006-1-17
As usually, there's more than one way to do it, here's one:
First find out what was last tuesday, easy as pie with strtotime:
$last_tuesday = strtotime('last tuesday');
After that you can get all the dates with the same method (using
$last_tuesday as a reference point instead of today so we don't get this
weeks "last wednesday" if it happens to be friday, but "last wednesday"
counting from last tuesday).
$last_monday = strtotime('last monday', $last_tuesday);
$last_friday = strtotime('last friday', $last_tuesday);
$last_thursday = strtotime('last thursday', $last_tuesday);
$last_wednesday = strtotime('last wednesday', $last_tuesday);
Now you can convert them to human readable formats using date:
echo date('Y-m-d', $last_monday); // for example
--
SETI @ Home - Donate your cpu's idle time to science.
Further reading at <http://setiweb.ssl.berkeley.edu/>
Kimmo Laine <an*******************@gmail.com.NOSPAM.invalid>