  | 
              
	              
	                
  
    
	 
        สอบถามเรื่องการคิวรี่ข้อมูลตามเวลาที่กำหนด เช่น 7:30 - 19:00 โชว์ข้อมูลช่วงกลางวัน และ 19:30 - 07:00 กลางคืน     | 
   
  
    |   | 
   
 
 
 
              
  
          
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 กลางวัน (PHP) 
$sql = "select * from TableA where OpTime between 
STR_TO_DATE(CONCAT(OpDate, ' 07:30:00'), '%Y-%m-%d %H:%i:%s') 
AND
STR_TO_DATE(CONCAT(OpDate, ' 19:00:00'), '%Y-%m-%d %H:%i:%s')
  
 
กลางคืน  (PHP) 
$sql = "select * from TableA where OpTime between 
STR_TO_DATE(CONCAT(OpDate, ' 19:30:00'), '%Y-%m-%d %H:%i:%s') 
AND
STR_TO_DATE(CONCAT(OpDate + INTERVAL 1 DAY, ' 07:00:00'), '%Y-%m-%d %H:%i:%s')
  
 
ลอง query ตัวนี้ดูก่อนครับ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2017-05-31 15:33:36 | 
                        By :
                            ccjpn | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 ได้แล้วนะครับ เอามาแชร์ 
 
Code (PHP) 
$date_start1="2017-05-30 07:30";
$date_end1=date("Y-m-d H:i",strtotime($date_start1." +12 hour"));
echo $date_end1."<br>";
$date_start2="2017-05-30 19:30";
$date_end2=date("Y-m-d H:i",strtotime($date_start2." +12 hour"));
echo $date_end2."<br>";
 
if(time()>=strtotime($date_start1) && time()<strtotime($date_end1)){
    $Where="production_time >= '$date_start1' AND production_time <'$date_end1'";
    echo "Yes";
}
if(time()>=strtotime($date_start2) && time()<strtotime($date_end2)){
    $Where="production_time >= '$date_start2' AND production_time <'$date_end2'";
    echo "Yes";
}
 
Code (PHP) 
                  $strSQLsum = "select production.production_time,production.production_date,sum(total40trip)as sum40trip,sum(total12trip)as sum12trip ,sum(total12trip1)as sum12trip1 ,sum(total16trip)as sum16trip,sum(total16trip1)as sum16trip1,sum(total25trip)as sum25trip,sum(total30trip)as sum30trip ,count(production_time )as numtrip,sum(toptrip)as sumtoptrip from production 
                where $Where";
                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2017-06-01 11:35:50 | 
                        By :
                            bondsanti | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
      		  
	
     | 
   
 
                 |