c# SQL语句

来源:百度知道 编辑:UC知道 时间:2024/09/23 13:28:50
我存储在数据库里面的时间类型是(年月日时分秒)的,但是现在我想通过从文本框输入一个一个(年月日)类型的时间去检索数据库,想要得到的数据是(数据库里的时间的年月日与输入的时间相同的记录),即通过输入一个0000—00-00这种类型的日期,检索数据库里datetime字段与所输入日期是同一天的所有记录(时分秒不管,只要年月日相同的都要)。麻烦高手帮忙啊,谢谢了!!

where datediff(day,字段名,你的日期)=0

select * from 表 where convert(varchar(10),日期字段,101)='月/日/年'

101 美国 mm/dd/yyyy
20 或 120 ODBC 规范 yyyy-mm-dd hh:mi:ss(24h)

示例
select convert(varchar(10),getdate(), 101)
select convert(varchar(10),getdate(), 102)

select * from where datetime = 输入日期%
%是通配符。也就是比如我们输入2009-01-21

select * from where datetime = 2009-01-21%
就会查出所有2009年1月21日的数据。

select * from tablename where convert(varchar(10),日期字段,120)=输入的日期

LZ的方法也可以

http://heisetoufa.javaeye.com/blog/236726