1

我需要获取结束日期和开始日期之差小于或等于 2 的总行数。但如果我的开始日期是 2012 年 11 月 29 日和结束日期是 12-03-2012 我应该得到 2 而不是 4 的差异,因为 2012 年 12 月 1 日是星期六,2012 年 12 月 2 日是星期日。

DateE 是开始日期 ReplayDate 是结束日期

SELECT  
   DATE_FORMAT(DateE, '%Y-%m-%d') AS startdate,
   DATE_FORMAT(ReplyDate, '%Y-%m-%d') AS replydate,   
   DATEDIFF(ReplyDate,DateE) as diff
FROM emailtodb.emailtodb_email 
WHERE 
   Status = 2  
AND
   DATEDIFF(ReplyDate,DateE)<=2
AND 
   DATE_FORMAT(DateE, '%Y-%m-%d') 
BETWEEN 
   '2012-11-29' AND '2012-12-12'  
AND 
   TIME_FORMAT(DateE, '%H:%i:00') 
BETWEEN 
   '00:00' AND '23:59' 
4

1 回答 1

0

您可以在 php 脚本中检查它。当您获取 startDate 和 endDate 和 dateDifference 然后检查

$startDay = date('l', $startDate);
$endDay = date('l', $endDate);

if ($dateDifference < 4){
     if ( $startDay == 'Saturday' || $startDay == 'Sunday' ){
        $dateDifference--;
     }
     if ( $endDay == 'Saturday' || $endDay == 'Sunday' ){
        $dateDifference--;
     }
 }
 else{
    $totalWeek = (int) $dateDifference / 7;
    $dateDifference -= ($totalWeek + 1)*2;

    if ($startDay == 'Saturday' && $endDay = 'Saturday')
        $dateDifference++;
    else if ($startDay == 'Sunday' && $endDay = 'Sunday')
        $dateDifference++;
    else
    {
         if($endDate == 'Saturday')
             $dateDifference++;
        if ($startDay == 'Sunday')
            $dateDifference++;
    }   
 }

我还没有编译代码,但我希望它能工作

于 2012-12-13T10:28:06.223 回答