[PHP] Re: Week calculating

2004-01-13 Thread nabil
sorry but what do u think about this ?

?php
for ($j=1;$j13;$j++) {
   for ($i=1;$i32;$i++) {
   $mk = mktime(0, 0, 0, $j, $i, 2004);
   $datex = date (l, $mk);
   $daterest = date (j/n/Y, $mk);
   if ($datex == Tuesday) {
   echo $datex..$daterest.br;
   }
   }
}
?

the problem that it outputs 6 weeks in March ... why ?



Nabil [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 Greetings;

 I need a help here ... I want to make function that return the dates of
 Tuesdays in a given year

 Example::

 Calc_Tuesdays (2004);

 //and it should return or echo
 2004-01-06
 2004-01-13
 2004-01-20
 2004-01-27
 2004-02-03
 .
 .
 etc   ofcourse it should echo 5 Tuesdays in March by example
 so it should depends on the year not only current day+7

 any help please !!
 Nabil


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



Re: [PHP] Re: Week calculating

2004-01-13 Thread Jason Wong
On Tuesday 13 January 2004 21:29, nabil wrote:
 sorry but what do u think about this ?

 ?php
 for ($j=1;$j13;$j++) {
for ($i=1;$i32;$i++) {
$mk = mktime(0, 0, 0, $j, $i, 2004);
$datex = date (l, $mk);
$daterest = date (j/n/Y, $mk);
if ($datex == Tuesday) {
echo $datex..$daterest.br;
}
}
 }
 ?

You don't need the nested for-loop. Just a single loop to increment the 'day', 
going from, say, 1 to 366 would do. mktime() will take care of the month 
automatically.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
I'm also pre-POURED pre-MEDITATED and pre-RAPHAELITE!!
*/

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



[PHP] Re: Week calculating

2004-01-13 Thread memoimyself
A quick idea that can probably be perfected:

?php

function calc_weekday_dates ($weekday, $year)
{
$weekday_options = array('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun');

// Check argument $weekday  
if( !in_array( strtolower($weekday), $weekday_options) )
{
return false;
}

// Check argument $year.
if( $year  1900 || $year  2050 )
{
return false;
}

$ini_date = mktime(0, 0, 0, 1, 1, $year);   // Jan. 1
$end_date = mktime(0, 0, 0, 12, 31, $year); // Dec. 31

// The array to be returned.
$weekday_dates = array();

// There are 86400 seconds in a day.
for( $i = $ini_date; $i = $end_date; $i += 86400 )
{
if( strtolower( date('D', $i) ) == strtolower($weekday) )
{
// Format the wanted dates.
$weekday_dates[] = date('y-m-d', $i);
}
}

return $weekday_dates;
}

$test = calc_weekday_dates ('Tue', 2004);
print 'pre';
print_r($test);
print '/pre';

?

Seems to work. Now you can improve on it.

Cheers,

Erik Fleischer


On 13 Jan 2004 at 15:07, nabil wrote:

 Greetings;
 
 I need a help here ... I want to make function that return the dates of
 Tuesdays in a given year
 
 Example::
 
 Calc_Tuesdays (2004);
 
 //and it should return or echo
 2004-01-06
 2004-01-13
 2004-01-20
 2004-01-27
 2004-02-03
 .
 .
 etc   ofcourse it should echo 5 Tuesdays in March by example
 so it should depends on the year not only current day+7
 
 any help please !!
 Nabil
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

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