Re: Calendar/Date
| From: | Robert Cummings | Date: | Wed, 18 Mar 2009 08:13:05 +0000 |
| Subject: | Re: Calendar/Date | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-290207@lists.php.net to get a copy of this message | ||
On Tue, 2009-03-17 at 20:52 -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
A sprinkle of math + a sprinkle of time + a sprinkle of PHP:
<?php
$dates = array();
$offset = (int)date( 'w' ) - 6;
for( $i = 0; $i < 7; $i++ )
{
$dates[] = date( 'l F j, Y', strtotime( '+'.($offset + $i).'
days' ) );
}
print_r( $dates );
?>
Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP