dsx5201 2013-09-05 20:43
浏览 28
已采纳

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

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

  • 写回答

5条回答 默认 最新

  • du8589840 2013-09-05 20:49
    关注

    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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题