select * from w_content where EmpName = 'wlz' and datediff(day,SubDate,'2003-7-18')=0原理:
select datediff(day,'2001-1-1','2002-1-1') 天
select datediff(month'2001-1-1','2002-1-1') 月
select datediff(year,'2001-1-1','2002-1-1') 年
---------------------------------------------------------------------------------
select * from w_content where EmpName = 'wlz' and CONVERT(varchar(10),SubDate,120)='2003-07-18'原理:
select CONVERT(varchar(10), getDate(),120) --不要时间2002-1-1
select convert(char(8),getdate(),112) ----20020101
select convert(char(8),getdate(),108) ---06:05:05
select datediff(day,'2001-1-1','2002-1-1') 天
select datediff(month'2001-1-1','2002-1-1') 月
select datediff(year,'2001-1-1','2002-1-1') 年
---------------------------------------------------------------------------------
select * from w_content where EmpName = 'wlz' and CONVERT(varchar(10),SubDate,120)='2003-07-18'原理:
select CONVERT(varchar(10), getDate(),120) --不要时间2002-1-1
select convert(char(8),getdate(),112) ----20020101
select convert(char(8),getdate(),108) ---06:05:05
and Replace(Convert(varChar(10),SubDate,20),'-0','')='2003-7-18'
select * from w_content where EmpName = 'wlz' and SubDate between
'2003-7-18' and '2003-7-19'
and convert(varhcar(10),SubDate,120) ='2003-7-18'
and convert(varhcar(10),SubDate,120) ='2003-07-18'
你有下面的方法试试:select * from w_content where EmpName = 'wlz' and convert(varvhar(10),SubDate,120) ='2003-07-18'
select * from w_content where EmpName = 'wlz' and datediff(day,SubDate,'2003-7-18')=0
or
select * from w_content where EmpName = 'wlz' and SubDate between
'2003-7-18' and '2003-7-19'
如果日期是字符型,
select * from w_content where rtrim(EmpName) = 'wlz' and rtrim(SubDate) ='2003-7-18'
所以如果你有的时间是2003-07-18 10:00:00.000的记录就无法取出了
所以如果你有的时间是2003-07-18 10:00:00.000的记录就无法取出了
所以如果你有的时间是2003-07-18 10:00:00.000的记录就无法取出了