如何将时间与数据库时间进行比较 [英] How to compare time with Database time's

查看:427
本文介绍了如何将时间与数据库时间进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有带有datetime数据类型的时间字段,即.来自&致

我为此插入了值,如下所示.

1早餐2012-04-05 07:00:00.000 2012-04-05 10:00:00.000
1午餐2012-04-05 11:00:00.000 2012-04-05 02:30:00.000


我需要准备以下存储过程..
输入参数:用户将通过时间作为输入,即8AM,1PM

输出:我需要检索所有值给用户.

如何将此输入时间与数据库时间进行比较?

在Advance中致谢

解决方案

尝试:

  DECLARE   @ TIME   TIME  = '  11PM'
选择 *  FROM  myTable 位置 转换(时间,myDateColumn)> = @ TIME 


Hi all,

I have time fields with datetime datatypes ie. From & To

I inserted values for that as follows.

1 Breakfast 2012-04-05 07:00:00.000 2012-04-05 10:00:00.000
1 Lunch 2012-04-05 11:00:00.000 2012-04-05 02:30:00.000


I need to prepare storedprocedure for following..
Input parameter: user will pass the time as input ie 8AM, 1PM

Output : i need to retrieve all values to the user.

How can i compare this input time to Database time?

Thanks in Advance

解决方案

Try:

DECLARE @TIME TIME = '11PM'
SELECT * FROM myTable WHERE CONVERT(time, myDateColumn)>=@TIME


这篇关于如何将时间与数据库时间进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆