PHP上的日期和小时问题

时间:2019-02-28 17:16:40

标签: php date logic hour

我有一个不活动的计算机的报告,该报告被日期间隔过滤

例如:从“ 2019-02-24”到“ 2019-02-26”

用户可以在过滤器上设置一个“班次”,例如:班次A,班次B和班次C

机器值来自BD:Maq 01:已停止'2019-02-24 09:00:00'返回了'2019-02-24 11:00:00'

每个班次都有特定的时间表

  

A班:05:00:00到13:30:00;

     

班次B:13:31:00至22:00:00;

     

班次C:22:01:00直到04:59:00;

所有值都转换为srtotime

假设用户选择了'2019-02-24'e'2019-02-26'和'shift'A之间的间隔(05:00到13:30):

   values from BD: Machine 01
    stopped '2019-02-24 09:00:00', returned: '2019-02-24 10:00:00' = 1 hour stopped on 24/02 shift  A;
    stopped '2019-02-25 12:00:00', returned: '2019-02-25 15:00:00' = 1:30 hours stopped on 24/02 shift  A;
    I would like to create this parameter, the code identify that the shift chosen is shift A (05:00 ás 13:30), in all day selected, and then compile everything
ex: Mach 01 = hours stopped between 24/02 and 26 on shift A: 02:30:00
到目前为止,我的代码:

    $data_ida = '2019-02-24';
    data_volta '2019-02-26'
    $sql_ = "SELECT * FROM manutencao WHERE data BETWEEN '$data_ida' - interval 90 day AND '$data_volta' AND h_retorno != '0000-00-00 00:00:00' ORDER BY id ASC";
            $disp_sql_ = $mysqli->query($sql_);
            $consulta  = $disp_sql_->num_rows;

            if($consulta > 0){
            while($data_2 = $disp_sql_->fetch_array())
            { 
                $h_stopped                = $data_2['h_parada'];
                $h_returned               = $data_2['h_retorno'];
                $num_mach                 = $data_2['num'];


                $day_begin       = strtotime($data_ida." 00:00:00");
                $day_end         = strtotime($data_volta." 23:59:00");
                $hour_begin_mach = strtotime($h_stopped);
                $hour_end_mach   = strtotime($h_retorned);



                if($hour_begin_mach >= $day_begin && $hour_end_mach <= $day_end){

                                       if($shift == 'a'){
                                            $shift_begin = '05:00:00';
                                            $shift_end   = '13:29:00';
                                        }elseif($shift == 'b'){
                                            $shift_begin = '13:30:00';
                                            $shift_end   = '22:00:00';
                                        }elseif($shift == 'c'){
                                            $shift_begin = '22:01:00';
                                            $shift_end   = '04:59:00';
                                        }
                    $strtotime_shift_begin =    strtotime($data_ida." ".$shift_begin);
                    $strtotime_shift_end   =    strtotime($data_volta." ".$shift_end);      



                if($strtotime_shift_begin <= $hour_begin_mach && $strtotime_shift_end   >= $hour_end_mach ){


                        $diff      = $hour_end_mach - $hour_begin_mach ;
                        $stopped []= array('machine' => $num_mach, 'seconds' => $diff);

                    }}

当日期之间的间隔大于1(例如24 / 02、25 / 02和26/02)时,我该如何在上面执行此代码?

抱歉英语不好

0 个答案:

没有答案