0

我尝试显示 1 个月度数据,但我想显示例如 01.06.2013 和 01.07.2013 之间?如何更改此查询以在两个日期之间显示?提前致谢

   select b.ID ID, bt.type BULTEN_TYPE, b.ID TOPIC, b.Bul_Effect EFFECTT, b.Bul_Comment COMMENTS, 

     concat(date_format(b.Bul_date,'%d.%m.%Y'), ' ', b.Bul_hour, ':', b.Bul_min) as BEGIN,      
     concat(date_format(b.bitdate,'%d.%m.%Y'), ' ', b.bithour
     , ':', b.bitmin) as FINISH from bulten b, bulten_type bt, statu s WHERE b.Bul_Type = bt.ID and   
      b.Status = s.ID and Bul_date >= date(now() - interval 1 month) order by ID desc;
4

4 回答 4

2
 select b.ID ID, 
      bt.type BULTEN_TYPE,
      b.ID TOPIC,
      b.Bul_Effect EFFECTT,
      b.Bul_Comment COMMENTS, 
     concat(date_format(b.Bul_date,'%d.%m.%Y'), ' ', b.Bul_hour, ':', b.Bul_min) as BEGIN,
     concat(date_format(b.bitdate,'%d.%m.%Y'), ' ', b.bithour
     , ':', b.bitmin) as FINISH 
     from bulten b, bulten_type bt, statu s
      WHERE b.Bul_Type = bt.ID and   
      b.Status = s.ID and 
     Month(Bul_date)=Month(GetDate()) and Year(Bul_date)=Year(GetDate()) 
     order by ID desc;
于 2013-07-24T09:15:01.267 回答
1

WHERE子句将为您提供您用作示例的确切内容:

... and Bul_date BETWEEN '1/6/2013' AND '1/7/2013' ...

现在,一种更动态的方式来获得我认为你想要的东西是:

... and Bul_date BETWEEN GETDATE() AND DATEADD(DAY, 1, GETDATE()) ...

从现在到一天后,这将为您提供一切。

现在,最后一个例子的问题是它GETDATE()有时间,所以如果你想去掉它(即从午夜开始)你可以这样做:

... and Bul_date BETWEEN DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE())) AND
        DATEADD(DAY, 1, DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE())))
于 2013-07-24T09:17:28.910 回答
1

用这个

Bul_date BETWEEN @StartDate AND @EndDate;
于 2013-07-24T09:19:26.197 回答
1

我为你找到了一些东西。我认为这可能会帮助你

SQL 检查两个日期和时间之间的记录

检查这个问题

于 2013-07-24T09:25:15.087 回答