sql中的时间格式,两次之间增加 [英] Times format in sql, have increment between two Times
本文介绍了sql中的时间格式,两次之间增加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好.
我想要两次之间以特殊增量进行收藏.
例如我有两次(08:00:00和16:00:00,并且也增加00:30:00)
我需要这些时间之间的所有时间,以这个增量,在这个例子中,它意味着:
Hi every one.
I want a collection between two times with special increment.
For example i have two times ( 08:00:00 And 16:00:00 , And also increment 00:30:00 )
I need all times between these times, by that increment, in this example it means :
{08:00:00 , 08:30:00, 09:00:00, 09:30:00, 10:00:00 , ... , , 16:00:00}
所以我想要一个选择"来做到这一点.
有什么建议吗?
预先感谢.
So i want a "Select" That do that.
Any suggestion please ?
Thanks in advance.
推荐答案
嗨阿明,
这是:
Hi Armin,
Here it is :
declare @st time
set @st = '8:0:0'
declare @ft time
set @ft = '16:0:0';
declare @interval int
set @interval = 30;
with a( gt )
as
(
select @st
union all
select dateadd(mi, @interval , gt) sequence from a where dateadd(mi, @interval , gt)<=@ft
)
select * from a
希望对您有所帮助.
Hope it helps.
尝试一下..
try this..
DECLARE @Start_Time DATETIME, @End_Time DATETIME
SET @Start_Time = CONVERT(DATETIME,'08:00:00',103)
SET @End_Time = CONVERT(DATETIME,'16:00:00',103)
WHILE(@Start_Time <= @End_Time)
BEGIN
SELECT CONVERT(VARCHAR(8),@Start_Time,108)
SET @Start_Time = (SELECT DATEADD(minute,30,@Start_Time))
END
希望这对您有帮助...
hope this helps...
这篇关于sql中的时间格式,两次之间增加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文