繁体   English   中英

"计算两个日期数组之间天数的更好方法"

[英]Better way to calculate days between two arrays of dates

我需要“更智能的代码”的帮助来计算 2 个数组之间的天数。 一个有 n 个预测日期,另一个有 n 个发生日期。 这些日期将在本文末尾的图表中使用。

            $expectedDate = array($res_query[0]['date_expect'], $res_query[1]['date_expect'], $res_query[2]['date_expect'], $res_query[3]['date_expect'], $res_query[4]['date_expect'] );

            $realDate = array($res_query[0]['date_real'], $res_query[1]['date_real'], $res_query[2]['date_real'], $res_query[3]['date_real'], $res_query[4]['date_real'] );

            $E0 = $expectedDate[0];
            $E1 = $expectedDate[1];
            $E2 = $expectedDate[2];
            $E3 = $expectedDate[3];
            $E4 = $expectedDate[4];

            $R0 = $realDate[0];
            $R1 = $realDate[1];
            $R2 = $realDate[2];
            $R3 = $realDate[3];
            $R4 = $realDate[4];

            $inter0 = strtotime($R0) - strtotime($E0);
            $days0 = floor($prazoM0 / (60 * 60 * 24));

            $inter1 = strtotime($R1) - strtotime($E1);
            $days1 = floor($prazoM1 / (60 * 60 * 24));

            $inter2 = strtotime($R2) - strtotime($E2);
            $days2 = floor($prazoM2 / (60 * 60 * 24));

            $inter3 = strtotime($R3) - strtotime($E3);
            $days3 = floor($prazoM3 / (60 * 60 * 24));

            $inter4 = strtotime($R4) - strtotime($E4);
            $days4 = floor($prazoM4 / (60 * 60 * 24));
?>


<? var $visitorsChart = $('#visitors-chart')
  var visitorsChart  = new Chart($visitorsChart, {
    data   : {
      labels  : ['1st', '2nd', '3rd', '4th', '5th', '6th', '7th', '8th', '9th', '10th'],
      datasets: [{
        type : 'line',
        **data                : [<?echo $days0?>,<? echo $days1?>,<? echo $days2?>,<?echo $days3?>,<?echo $days4?>],**
        backgroundColor     : 'transparent',
        borderColor         : '#007bff',
        pointBorderColor    : '#007bff',

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM