从指定的日期时间比较当前的日期时间 [英] Compare current DateTime from Specified DateTime
本文介绍了从指定的日期时间比较当前的日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我的表中有两个字段.一个是startTime&另一个是Endtime.
我想确定从屏幕输入的时间是否在数据库开始时间&之间;时间结束 .
Hi
i have two fields in my Table . one is startTime & other is Endtime .
I want to find whether the input time from screen lies in between the DB starttime & End Time .
Sample DB Values
StartTime ENDTime
8.00 15.00
假设用户在屏幕上输入10.00.现在,我需要检查输入的时间是否介于开始时间和开始时间之间.结束时间.
Suppose the user enter 10.00 in screen . now i need to check whether the entered time lies in between start & end time .
推荐答案
您可以使用BETWEEN比较来测试时间.例如,考虑以下内容:
You can use the BETWEEN comparison to test the time. For example, consider the following:
declare @start as time
declare @end as time
declare @test1 as time
declare @test2 as time
begin
set @start = cast('08:00' as time)
set @end = cast('15:00' as time)
set @test1 = cast('10:00' as time)
set @test2 = cast('20:00' as time)
if @test1 between @start and @end begin
print '@test1 is between';
end;
if @test2 between @start and @end begin
print '@test2 is between';
end;
end;
go
两者之间可以在查询中用作条件等.如果使用日期时间,则必须剥离日期部分.例如:
The between can be used in a query as a condition etc. If you''re using a datetime then you have to strip off the date portion. For example:
select cast(getdate() as time)
这篇关于从指定的日期时间比较当前的日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文