如何在一周和几年之间找到一周的差异

I have a set of weeks and years like

$wk_det1 = array(36,2013);//ISO week assuming 52 weeks in a year, Year the said week belongs to
$wk_det2 = array(51,2012);

I need to find difference in weeks between $wk_det1 and $wk_det2. This might be simple but I can't quite figure it out. Any ideas how to do this?

PS: this is for php4, just in case

Each year has 52 weeks, so 2013 years is 2013*52 weeks, and 2011 years is 2011*52 weeks; the difference between the two (given that they are in the same week) is 52*(2013-2011) weeks.

The difference can be expressed simply as 52*($wk_det2[1]-$wek_det1[1])+$wk_det2[0]-$wk_det1[0];.

The logic works like this:

define("WEEKS_PER_YEAR", 52);

$week1_yr = $wk_det1[1];
$week2_yr = $wk_det2[1];
$yr_diff = $week2_yr - $week1_yr;

$week1_wk = $wk_det1[0];
$week2_wk = $wk_det2[0];
$wk_diff = $week2_wk - $week1_wk;

$total_wk_diff = WEEKS_PER_YEAR*$yr_diff+$wk_diff;

Whenever you're working with dates in php, it's always strtotime.

In this case, you can convert the week and year using the following notation:

strtotime("2013W36");

then you can do simple integer arithmetic with the resulting timestamps.

$timediff = strtotime("2013W36") - strtotime("2012W51");
$weeks = $timediff / (3600 * 24 * 7); // 3600 seconds in hour
$preetyWeeks = number_format($weeks, 2);
if($wk_det1[1] >= $wk_det2[1]) {
    $a = $wk_det1;
    $b = $wk_det2;
}
else {
    $a = $wk_det2;
    $b = $wk_det1;
}
$years_in_between = $a[1] - $b[1] - 1;

$more_weeks = 52 * $years_in_between;

$weeks_a = $a[0];
$weeks_b = 52 - $b[0];

$difference_weeks = $week_b + $more_weeks + $week_a;
<?php
$end = strtotime("2013W36");
$start = strtotime("2011W51");
$delta = $end - $start;
$one_week = 60 * 60 * 24 * 7;
$modulus = $delta % $one_week;
$delta = $delta - $modulus;
$week_delta = $delta / $one_week;
echo "There are $week_delta weeks between $end and $start with modulus $modulus";
?>

Output: There are 88 weeks between 1378094400 and 1324270800 with modulus 601200