c#数据库获取时间

来源:百度知道 编辑:UC知道 时间:2024/06/06 08:27:47
数据库里有张表,表中有时间字段,数据类型是datetime。
请问高手们,怎样才能用数据库语言查询到和系统时间月份一样的所有记录,
就是当前月份的所有记录

select * from table_name where left(time,5)=left(getdate(),5)

'select * from table where Convert(Varchar,时间字段,112) = '+DataTime.Year.ToString()+DataTime.Month.ToString()

SELECT * FROM yourtable where createdate between cast(cast(year(getdate()) as varchar(4)) + '-' + cast(month(getdate()) as varchar(2)) + '-1' as datetime) and
dateadd(day, -1,cast(cast(year(getdate()) as varchar(4)) + '-' + cast(month(getdate()) + 1 as varchar(2)) + '-1' as datetime))

oracle
select * from tb where trunc(fieldname,'mm')=trunc(sysdate,'mm')