检查startdate或结束日期是否在上周

时间:2016-01-25 12:52:41

标签: mysql sql

我想检查startdate或enddate是否在上周。我想显示commRunStart或commRunEnd日期在上周的行。

 SELECT A.commRunStart, A.commRunEnd FROM  `commRuns` AS A
 WHERE A.commRunStart >= CURDATE( ) - INTERVAL DAYOFWEEK( CURDATE( ) ) +6 DAY
    OR A.commRunEnd < CURDATE( ) - INTERVAL DAYOFWEEK( CURDATE( ) ) -1 DAY 

1 个答案:

答案 0 :(得分:3)

 SELECT A.commRunStart, A.commRunEnd FROM  `commRuns` AS A
 WHERE (A.commRunStart >= CURDATE( ) - INTERVAL DAYOFWEEK( CURDATE( ) ) +6 DAY
    AND A.commRunStart < CURDATE( ) - INTERVAL DAYOFWEEK( CURDATE( ) ) -1 DAY )
    OR (A.commRunEnd >= CURDATE( ) - INTERVAL DAYOFWEEK( CURDATE( ) ) +6 DAY
    AND A.commRunEnd < CURDATE( ) - INTERVAL DAYOFWEEK( CURDATE( ) ) -1 DAY )