doukeyong3746487 2015-07-25 09:18
浏览 8

PHP中的两小时总时数和差异

i want one feature,that employee can apply for permission in a month not exceeding 4 hrs in total for a month. So before applying this, im checking database ,and totalling all hours sum of all ( totime- fromtime). and checking whether the hours is more than 4. I tried below code..but exactly i cannot get my need..

$total = $this->getTotalHours($emp->id,$req->perdate);          
if($total > 4)
        {
            error_log("You cannot apply more than 4 hours");            
        }


private function getTotalHours($empid,$PerDate){
        $amount = 0;
        $newmonth = date('F', strtotime($PerDate));
        $empPer = new EmployeePermission();
            $leaveDays = $empPer->find("employee = ?",array($empid));
            foreach($leaveDays as $leaveDay){
                $month = date('F', strtotime($leaveDay->applydate));
                if($newmonth == $month){                    
                      $diff = (strtotime($leave->totime) - strtotime($leave->fromtime);
                }
                $amount += $diff;                   
            }
        return $amount;         
    }

If the month while applying is july, then im checking and getting all entries in july month for that employee in database,and accumulating it and finally i have to check that.If the hour is morethan 4 hrs, then he cannot apply permission.

Edited: My requirement is, i want the total hours taken per month in Hours,Minute format. Database:

 employee   applydate   fromtime    totime         status
    169     2015-07-24  14:08:37    13:08:37        Approved
    111     2015-07-25  11:12:26    11:30:26        Pending
    111     2015-07-25  12:14:13    12:36:13        Pending
    169     2015-07-27  12:00:00    14:30:00        Pending
    169     2015-07-29  14:00:00    15:00:00        Pending
    111     2015-07-27  16:11:26    17:11:26        Pending
  • 写回答

2条回答 默认 最新

  • dongliping003116 2015-07-25 09:27
    关注

    In your code $amount is in "strtotime" format, I think you need to convert it into hrs..

    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c