tags:

views:

79

answers:

5

Hi, How to convert a week number to a month ?

For example, 162 weeks = 37,26 Month (so 37 Months if we around the number).

Have you an idea ?

A: 

If you need an average value:

return $numberOfWeeks * 0.229984378;

Source: http://www.google.com/search?q=1%20week%20in%20months=

(However, bear in mind that the number of weeks in a month is not constant. 1 month may contain 4 to 4.4 weeks.)

KennyTM
A: 

You need to have a starting date: eg. 162 weeks from ....

Parkyprg
this only depends on the accuracy required. if it doesn't mather how accurate it is then 30 days for one month is accurate enough because the average is about 30.416 days a month
ITroubs
A: 

that is almost trivial depenging on the accuracy you need

$days = $weeks * 7;
$months = floor($days/30);
ITroubs
Perfect, thanks !
bahamut100
Precise date/time calculations are **never** trivial.
0xA3
it is regarding the difficulty of the calculation
ITroubs
+2  A: 

You can use the DateTime object for this. Create a new date, that starts on january first, then use the add method, using a DateInterval object of x weeks (new DateInterval('P' . $num . 'W');), then format the date object using the month character.

Peter Kruithof
Thanks, I keep this fix for the future.
bahamut100
A: 

1 month is 4.34812141 weeks.

So it would be:

$months = $weeks / 4.34812141;

If you want to round it up. You need to:

echo (int)$months;
Ruel
Thank, it works
bahamut100