dpa89292 2017-03-23 22: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-23 22: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.

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部