dpa89292 2017-03-24 06:32
浏览 42
已采纳

通过php脚本消除周末(周日)

I am trying to count number of working days available for particular hours set. here i just need to exclude Sundays by the following php script. if this script find a Sunday this should increase the count. its working but,

This script is capable to exclude first 'Sunday' but not the 'second' and 'third'. kindly give me a solution to correct this

function testRange() {
            $phone_Quantity = 0;
            $phone_Quantity = $_POST['phoneQuantity'];
            if ($phone_Quantity > 0 && $phone_Quantity <= 300) {
                return 300;
            } elseif ($phone_Quantity >= 301 && $phone_Quantity <= 600) {
                return 600;
            } elseif ($phone_Quantity >= 601 && $phone_Quantity <= 900) {
                return 900;
            } elseif ($phone_Quantity >= 601 && $phone_Quantity <= 1200) {
                return 1200;
            } elseif ($phone_Quantity >= 1201 && $phone_Quantity <= 1500) {
                return 1500;
            } elseif ($phone_Quantity >= 1501 && $phone_Quantity <= 1800) {
                return 1800;
            }
        }


        echo testRange();
        $query_to_get_hours = "SELECT
cdma_filtering_target_hours.Target_hours
FROM
cdma_filtering_target_hours
WHERE
cdma_filtering_target_hours.No_of_units='" . testRange() . "'
";
        $query_to_get_hours_query = $system->prepareSelectQuery($query_to_get_hours);
        foreach ($query_to_get_hours_query as $THours) {
            $targeted_hours = $THours['Target_hours'];
        }


        $hid = 24; // Hours in a day - could be 24, 48, etc
        $days = round($targeted_hours / $hid);


        for ($xdays = 0; $xdays < $days; $xdays++) {
            if (date('l', strtotime(date('y-m-d', strtotime("+$xdays days")))) == 'Sunday') {

                $days++;
                break;
            }
        }
  • 写回答

1条回答 默认 最新

  • dongxu4580 2017-03-24 06:51
    关注

    Why do you converting +$xdays string representation twice?

    If you comment your if statement and add next line

    echo date('l', strtotime("+$xdays days"));
    

    you can clearly see that it works.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度