On Tue, Mar 17, 2009 at 08:52:11PM -0700, Jason Todd Slack-Moehrle wrote:

> Hi All,
> Does anyone have code and/or advice for how to get get the current
> week (with a passed current day, say) and what then end date is at
> Saturday.
> So take today: Tuesday March 17, 2009
> I want to get:
> Sunday March 15, 2009
> Monday March 16, 2009
> Tuesday March 17, 2009
> Wednesday March 18, 2009
> Thursday March 19, 2009
> Friday March 20, 2009
> Saturday March 21, 2009

I just answered a question similar to this. You might check the
archives. In this case, you'll need to use the getdate() function (see
php.net/manual/en/ for details) to get the array of values for today
(like the day of the month, month number, year, etc.). The getdate()
function returns an array, one of whose members is 'wday', which is the
day of the week, starting with 0 for Sunday. Use that number to
determine how many days to go back from today. Then use mktime() to get
the timestamps for each day in turn. You feed mktime() values from the
getdate() call. Then you can use strftime() or something else to print
out the dates in whatever format, given the timestamps you got.

Be careful in feeding values to mktime(). If your week spans a
month or year boundary, you'll need to compensate for it when giving
mktime() month numbers, day numbers and year numbers.


Paul M. Foster

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to