I tried display 1 monthly data but I want display e.g between 01.06.2013 and 01.07.2013 ? How to change this query for display between two date ? Thanks in advance
我尝试显示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;
4 个解决方案
#1
1
This WHERE
clause will get you exactly what you used as an example:
这个WHERE子句将为您提供您用作示例的内容:
... and Bul_date BETWEEN '1/6/2013' AND '1/7/2013' ...
Now, a more dynamic way of getting at what I think you want would be:
现在,一种更有活力的方式来获得我认为你想要的东西:
... and Bul_date BETWEEN GETDATE() AND DATEADD(DAY, 1, GETDATE()) ...
that would get you everything between now, and a day from now.
从现在开始,从现在开始,这将使你获得一切。
Now, the problem with the last example is that GETDATE()
has a time on it so if you wanted to strip that (i.e. to start from midnight) you could do this:
现在,最后一个例子的问题是GETDATE()有一个时间,所以如果你想剥离它(即从午夜开始)你可以这样做:
... and Bul_date BETWEEN DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE())) AND
DATEADD(DAY, 1, DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE())))
#2
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;
#3
1
use this
用这个
Bul_date BETWEEN @StartDate AND @EndDate;
#4
1
I have find something for you. I think this might helps you
我找到了适合你的东西。我想这可能会对你有所帮助
SQL check record in between two dates and time
两个日期和时间之间的SQL检查记录
Check this question
检查这个问题
#1
1
This WHERE
clause will get you exactly what you used as an example:
这个WHERE子句将为您提供您用作示例的内容:
... and Bul_date BETWEEN '1/6/2013' AND '1/7/2013' ...
Now, a more dynamic way of getting at what I think you want would be:
现在,一种更有活力的方式来获得我认为你想要的东西:
... and Bul_date BETWEEN GETDATE() AND DATEADD(DAY, 1, GETDATE()) ...
that would get you everything between now, and a day from now.
从现在开始,从现在开始,这将使你获得一切。
Now, the problem with the last example is that GETDATE()
has a time on it so if you wanted to strip that (i.e. to start from midnight) you could do this:
现在,最后一个例子的问题是GETDATE()有一个时间,所以如果你想剥离它(即从午夜开始)你可以这样做:
... and Bul_date BETWEEN DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE())) AND
DATEADD(DAY, 1, DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE())))
#2
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;
#3
1
use this
用这个
Bul_date BETWEEN @StartDate AND @EndDate;
#4
1
I have find something for you. I think this might helps you
我找到了适合你的东西。我想这可能会对你有所帮助
SQL check record in between two dates and time
两个日期和时间之间的SQL检查记录
Check this question
检查这个问题