有个DATETIME型字段怎样查询解决方案
有个DATETIME型字段怎样查询
有个thedate 的字段
select * from info where thedate = '2012-3-19'没结果
但是
select * from info where thedate> = '2012-3-18'就有 2012-3-19号的两条记录,碰上这种情况应该怎样查?
------解决方案--------------------
datediff(day,‘2012-3-19’,thedate)
------解决方案--------------------
有个thedate 的字段
select * from info where thedate = '2012-3-19'没结果
但是
select * from info where thedate> = '2012-3-18'就有 2012-3-19号的两条记录,碰上这种情况应该怎样查?
------解决方案--------------------
datediff(day,‘2012-3-19’,thedate)
------解决方案--------------------
- SQL code
select * from info where datediff(day,'2012-03-18',thedate) >=0
------解决方案--------------------
- SQL code
SELECT * FROM info WHERE thedate BETWEEN '2012-03-18 00:00:00' AND '2012-03-18 23:59:59'
------解决方案--------------------
你的时间是datetime类型,第一个查不到应该是因为日期后面的时分秒。可以这样试试:convert(varchar(10),thedate,120)='2012-03-19'
------解决方案--------------------
- SQL code
select * from info where convert(char(10),thedate,120) = '2012-03-19' ----这样就有结果,你日期是不是包含时间。
------解决方案--------------------