求一个关于时间比较的存储过程(急)

theNull 2006-06-08 10:23:26
表VoxPath有字段LoginTimeFrom和LoginTimeTo,分别存储时间的起始和终止小时(例如,8和20)

如何取得当前服务器时间的小时(24小时制),判断它是否处于LoginTimeFrom和LoginTimeTo的整型数值内? 如果在此范围内,则返回true,否则返回false。
请用存储过程,谢谢!
...全文
243 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
LouisXIV 2006-06-08
  • 打赏
  • 举报
回复
没有其他限制条件??

create procedure sp_timecompare
as
declare @a varchar(10)
if datepart(hh,getdate()) between (select LoginTimeFrom from VoxPath) and (select LoginTimeTo from VoxPath)
set @a='True'
else
set @a='False'
select @a
go

OracleRoob 2006-06-08
  • 打赏
  • 举报
回复
--改

create procedure sp_test
as
begin

declare @i int

set @i = datepart(hour,getdate())

if @i>=LoginTimeFrom and @i<=LoginTimeTo
print 'true'
else
print 'false'
end
go
xeqtr1982 2006-06-08
  • 打赏
  • 举报
回复
create table a(LoginTimeFrom int,LoginTimeTo int)
insert into a select 8,20
go

create proc aa
as

if exists(select 1 from a where datepart(hour,getdate()) between LoginTimeFrom and LoginTimeTo)
print 'true'
else
print 'false'

go

exec aa

drop table a
drop proc aa
OracleRoob 2006-06-08
  • 打赏
  • 举报
回复
create procedure sp_test
as
begin

declare @i int

set @i = datepart(hour,getdate())

if @i=LoginTimeFrom and @i<=LoginTimeTo
print 'true'
else
print 'false'
end
go
lxzm1001 2006-06-08
  • 打赏
  • 举报
回复
create proc test
as
begin
if select datediff(hh,LoginTimeFrom,LoginTimeTo)<=24
print 'true'
else
print 'false'
end
lw1a2 2006-06-08
  • 打赏
  • 举报
回复
select * from VoxPath
where datepart(hh,getdate())>=LoginTimeFrom and datepart(hh,getdate())<=LoginTimeTo

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧