duanhegn231318 2014-07-17 12:41
浏览 45
已采纳

PHP日期不包括周末

I am currently doing a website which offers delivery Monday through Friday only.

I am trying to figure out how to add delivery date. For e.g:

"Order today and you can expect delivery on DD/MM/YY"

The above date would require to exclude any weekends

So basically if ordered today the delivery day is 4 working days later excluding weekends.

  • 写回答

3条回答 默认 最新

  • duanmu0834 2014-07-17 13:08
    关注

    Try this logic. You can modify it according to your needs.

        $curdate = '2014-07-19';
        $mydate=getdate(strtotime($curdate));
        switch($mydate['wday']){
            case 0: // sun
            case 1: // mon
                $days = 4;
                break;
            case 2:    
            case 3:
            case 4:
            case 5:
                $days = 6;
                break;
            case 6: // sat
                $days = 5;
                break;
        }
        echo date('Y-m-d', strtotime("$curdate +$days days"));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 ubuntu服务器配置dns域名后无法访问其他域名
  • ¥50 本人复制了一个关于股票指标的代码,但是运行失败,有没有人帮我解决一下
  • ¥50 用matlab和numeca做透平机械流体力学和热力学模拟 价格可议
  • ¥15 Unity3D WebView
  • ¥20 论文AlphaTensor复现(有偿)
  • ¥15 (有偿)在ANSYS中 .anf文件
  • ¥45 关于#芯片#的问题:组合逻辑电路设计
  • ¥15 基与机器学习和时间序列分析预测养老服务需求趋势
  • ¥100 求连续两帧图像在水平和垂直上偏移
  • ¥15 Verilog hdl密码锁设计