我尝试显示1个月度数据,但我希望显示例如2013年6月1日到2013年7月1日之间?如何更改此查询以显示两个日期之间?提前致谢
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;
答案 0 :(得分: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;
答案 1 :(得分: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())))
答案 2 :(得分:1)
使用此
Bul_date BETWEEN @StartDate AND @EndDate;
答案 3 :(得分:1)