3

Possible Duplicate:
Calculating days of week given a week number

In PHP you can get the number of week with 'date('W');' and it will return ISO-8601 week number of year

Now how I can get the days of an specific week and the month(s) ?

Update: For example I know 'Monday the 12th week of 2011' and want to get '31st March'

Community
  • 1
  • 1

4 Answers4

1

For days in a month you can use cal_days_in_month and for days in a specified week you can check out the following question: Calculating days of week given a week number

Community
  • 1
  • 1
The Pixel Developer
  • 13,282
  • 10
  • 43
  • 60
1
$start = strtotime('this Sunday');
$finish = strtotime('this Saturday');

$days = array();

while ($start <= $finish) {
   $days[] = date('d-m', $start);
   $start += strtotime('+1 day', 0);
}

var_dump($days);

CodePad.

Output

array(7) {
  [0]=>
  string(5) "24-04"
  [1]=>
  string(5) "25-04"
  [2]=>
  string(5) "26-04"
  [3]=>
  string(5) "27-04"
  [4]=>
  string(5) "28-04"
  [5]=>
  string(5) "29-04"
  [6]=>
  string(5) "30-04"
}
Community
  • 1
  • 1
alex
  • 479,566
  • 201
  • 878
  • 984
0

Check out the docs at http://php.net/manual/en/function.date.php

I think you want date('d') and date('F').

Ethan
  • 400
  • 3
  • 14
  • Thanks for your answer but that is for today not an specific day of a specific week. –  Apr 24 '11 at 15:14
  • True, but you can just pass in your desired date as the second param, like @fingerman has above. PHP's date functions are very flexible. – Ethan Apr 24 '11 at 15:49
0

I got somthing for you:

// Prints: July 1, 2000 is on a Saturday
echo "July 1, 2000 is on a " . date("l", mktime(0, 0, 0, 7, 1, 2000));

you can also do:

// out: July 1,2000 is on the 7th day
echo "July 1, 2000 is on the " . date("N", mktime(0, 0, 0, 7, 1, 2000)) ."th day";  

http://php.net/manual/en/function.date.php http://www.php.net/manual/en/function.mktime.php

fingerman
  • 2,440
  • 4
  • 19
  • 24