If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

There's no easy way to do this...you'll have to use some calculations. I think this is a way:

Multiply the number of weeks by 7, to get a day in the specified week. Now subtract the weekday from that day. So for example, if the day was December 31, then it's tuesday, and you'd subtract 1 to get Monday's date.

Of course, it's a bit more complicated than what I just explained, but what I said is just the general algorithm, you'll have to figure out the special cases.

The first ISO week of the year is the one with the first Thursday of the year in it. So let's see what day of the week January 1 of the $year was.

PHP Code:

$Jan1 = mktime(1,1,1,1,1,$year);
$weekdayJan1 = date('w',$Jan1);

The exact time doesn't really matter - I just felt like specifying 01:01:01.

Thursday is day number 4. So if January 1 was day $weekdayJan1, then the Thursday of the first week would be (11-$weekdayJan1)%7 days later (with the extra 7s there in case Jan 1 actually belonged to the last week of the previous year), and that first week started on the previous Monday (three days earlier than the Thursday, i.e., (11-$weekdayJan1)%7-3 days after Jan 1).
A table that illustrates that expression:

And code that uses it to get a timestamp for the Monday of the first week of the year:

PHP Code:

$FirstMonday = strtotime(((11-$weekdayJan1)%7-3) . ' days', $Jan1);

Of course the first Monday of the current $week is $week-1 weeks later than that:

PHP Code:

$CurrentMonday = strtotime(($week-1) . ' weeks', $FirstMonday);

$FirstMonday can be dropped and $CurrentMonday found with a single call strtotime(), passing it a string of the form "n weeks m days"; so an entire WeekToDate($week,$year) function can be written in three or four lines, viz:

Tuesday, of course, is one day later, Wednesday is two days later, and so on. Sunday (according to ISO) is six days later, but you may reckon it's one day earlier. No, it doesn't format the result into any particular form. This function is not the place to be doing that sort of thing.

The first if statement adjusts so that Sunday appears at the end of the week, not the beginning (which was needed for my purpose), but you could even optimize it to one line if you wanted to get rid of that, and just use date("w") - 1 in the strtotime statement?

OK, for anyone who wants another approach, I did this, it seems quite simple, and it works as well:

The original poster didn't have the exact date, only the week number and year. So for that code to be appropriate, you'd need a way to find the date given the week number and year. Which is the original problem.