0

我有一组周和年

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

我需要找出 $wk_det1 和 $wk_det2 之间的周数差异。这可能很简单,但我无法弄清楚。任何想法如何做到这一点?

PS:这是针对php4的,以防万一

4

5 回答 5

3

每年有52周,所以2013年是2013*52周,2011年是2011*52周;两者之间的差异(假设它们在同一周)是 52*(2013-2011) 周。

差异可以简单地表示为52*($wk_det2[1]-$wek_det1[1])+$wk_det2[0]-$wk_det1[0];

逻辑是这样工作的:

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;
于 2013-09-05T20:49:12.087 回答
1

每当您在 php 中处理日期时,它总是strtotime

在这种情况下,您可以使用以下符号转换周和年:

strtotime("2013W36");

然后您可以对生成的时间戳进行简单的整数运算。

于 2013-09-05T20:52:31.290 回答
0
<?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";
?>

输出:在 1378094400 和 1324270800 之间有 88 周,模数为 601200

于 2013-09-05T21:10:05.010 回答
0
$timediff = strtotime("2013W36") - strtotime("2012W51");
$weeks = $timediff / (3600 * 24 * 7); // 3600 seconds in hour
$preetyWeeks = number_format($weeks, 2);
于 2013-09-05T20:57:43.127 回答
0
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;
于 2013-09-05T20:57:55.270 回答