Sql server 如何在ms sql中查询where date with time=date without time
我想查询日期这是我的示例tsql:Sql server 如何在ms sql中查询where date with time=date without time,sql-server,Sql Server,我想查询日期这是我的示例tsql: select * from Bookings where StartTime = '2/15/2014' starttime的值为“2014年2月15日12:00:00 AM” 当我查询没有时间的StartTime=date时,结果是0 有人能帮我怎么做吗 谢谢像这样试试 SELECT * FROM Bookings WHERE Convert(VARCHAR(10),StartTime,101) = Convert(Varchar(10),'2/15/
select * from Bookings where StartTime = '2/15/2014'
starttime的值为“2014年2月15日12:00:00 AM”
当我查询没有时间的StartTime=date时,结果是0
有人能帮我怎么做吗
谢谢像这样试试
SELECT * FROM Bookings WHERE Convert(VARCHAR(10),StartTime,101) = Convert(Varchar(10),'2/15/2014',101)
如果您使用的是SQL SERVER 2012
试试这个
SELECT * FROM Bookings WHERE FORMAT(StartTime,'M/dd/yyyy') = FORMAT('2/15/2014','M/dd/yyyy')
“2014年2月15日”可以根据您所在的地区进行不同的解释。尝试使用ISO日期文字“2014-02-15”,它独立于区域设置
select * from Bookings where StartTime = '2014-02-15'
或者如果StartTime包括小时:
select * from Bookings where StartTime >= '2014-02-15' and StartTime < '2014-02'16'
从StartTime>='2014-02-15'和StartTime<'2014-02'16'的预订中选择*
最好的方法是进行简单的比较:
select *
from Bookings
where StartTime >= cast('2014-02-15' as date) and StartTime < cast('2014-02-14' as date);
我相信你也可以这样做:
select * from Bookings where StartTime::date = '2014-2-15'
STartTime是VarChar吗?如果是,将字符串转换为日期并进行比较,则此选项有效。但这个想法来自于您的分享再次感谢选择*来自预订,其中格式(开始时间,'M/dd/yyyy')='2/15/2014'
select * from Bookings where StartTime::date = '2014-2-15'