-3

I want to find the month number by given year and given week number, example- if my year: 2017 and week number is: 25 what will be the month.

Dev
  • 181
  • 12
  • @cb0 not tried yet. nothing found any where how to do this. – Dev Jan 13 '17 at 13:45
  • http://stackoverflow.com/questions/659183/how-do-i-get-the-month-number-from-the-year-and-week-number-in-c here is the solution but it is in c# – Dev Jan 13 '17 at 13:50
  • You also have to have a specific date to get the correct month number. E.g. the 5th week in 2017 is spanning end of Jan and beginning of Feb. A naive approach would be: Every year has 52 weeks, and every month has 4 weeks. Think about this for a moment! – cb0 Jan 13 '17 at 14:05

1 Answers1

2

Try this:

$date = new DateTime( "01.01.2017" ); // set datetime to 1, January 2017
$date->modify( "+21 weeks" ); // add 21 weeks
echo $date->format( "m" ); // echo month
oski225
  • 122
  • 2
  • 10