Re: Calendar Problem
| From: | tedd | Date: | Wed, 12 Aug 2009 13:20:19 +0000 |
| Subject: | Re: Calendar Problem | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-296691@lists.php.net to get a copy of this message | ||
At 4:08 PM -0400 8/11/09, Robert Cummings wrote:
tedd wrote:Rob: That's slick -- you never let me down with your simplicity and creativity. My solution was to find the next Friday and then cycle through +-28 days (four weeks) from that date, like so: <?php $fridays = array(); for( $i = 1; $i <= 7; $i++ ) { $time = strtotime( $i . ' day' ); if( date( 'D', $time ) == 'Fri' )Hi gang: I want to show the dates for all Fridays +-30 days from a specific date. For example, given today's date (8/11/2009) the Fridays that fall +-30 days are July 17, July 24, July 31, Aug 7, Aug 14, Aug 21, Aug 28, and Sept 4. I'm curious, how would you guys solve this?<?php $fridays = array(); for( $i = -30; $i <= 30; $i++ ) {$mod = $i < 0 ? $i : '+'.$i;$time = strtotime( $mod.' day' );if( date( 'D', $time ) == 'Fri' ) { $fridays[] = date( 'Y-m-d', $time ); }} print_r( $fridays ); ?> Cheers, Rob.
{
$start = 28 - $i;
$end = 28 + $i;
}
}
for( $i = -$start; $i <= $end; $i += 7 )
{
$time = strtotime( $i . ' day' );
$fridays[] = date( 'Y-m-d', $time );
}
print_r( $fridays );
?>
Your solution had 61 iterations (for loop) while mind had only 21, so mine's a bit faster. Here's the comparison:
http://php1.net/b/fridays/
But I'll use your solution -- it's more elegant.
Thanks for the code,
tedd
--
-------
http://sperling.com http://ancientstones.com http://earthstones.com