# How to get current week?

How do I found out what is the current week?

For example:

4th = would be 1st first week
16th = 2 week
30th = 4 week

I tried echo ceil(date(‘j’) / 7 );
but that does not work correctly.

No that is wrong, sorry you miss understood my question.

I meant to find out what is the current week of this month.

today is 27th, so output should be 4 week.

if today is 5th, so output would be 1st week.

``````
<?php
echo date(
'W',
strtotime(
date('F 4')
)
); #31
?>

``````

Not the best solution I’m sure.

Edit

Gah! I misread what you needed, I’ll go back to the drawing board. Do you want the weeks to start from the first of the month, or sunday/monday before/after the first? (delete as appropriate)

As I’m sure the interpreter would be as confused as I am… Of which month?

AnthonySterling current month.

Here’s a quick pointer.

``````
<?php

function getWeekNumber(\$day){

#you need to build this, but not with these values obviously
\$dates = array(
1 => range(1, 7),
2 => range(8, 14),
3 => range(15, 21),
4 => range(22, 28),
5 => range(29, 31),
);

foreach(\$dates as \$week_num => \$week){
if(in_array(\$day, \$week)){
return \$\$week_num;
}
}

return false;
}

echo getWeekNumber(18); #3

?>

``````