Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $tuesday = strtotime('last Tuesday');
- // check if we need to go back in time one more week
- $tuesday = date('W', $tuesday)==date('W') ? $tuesday-7*86400 : $tuesday;
- $tuesday = date('W', $tuesday)==date('W') ? $tuesday-7*86400+7200 : $tuesday;
- echo strtotime('last Tuesday');
- $z = date("Y-m-d", strtotime("last Saturday"));
- $z = (date('W', strtotime($z)) == date('W')) ? (strtotime($z)-7*86400+7200) : strtotime($z);
- print date("Y-m-d", $z);
- // test: find last date for each day of the week
- foreach (array('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun') as $day) {
- print $day . " => " . date('m/d/Y', last_dayofweek($day)) . "n";
- }
- function last_dayofweek($day)
- {
- // return timestamp of last Monday...Friday
- // will return today if today is the requested weekday
- $day = strtolower(substr($day, 0, 3));
- if (strtolower(date('D')) == $day)
- return strtotime("today");
- else
- return strtotime("last {$day}");
- }
Add Comment
Please, Sign In to add comment