根据时间搜索数据

来源:互联网 发布:linux snmp测试 编辑:程序博客网 时间:2024/05/16 16:00

上日数据

 convert(int,convert(char(10),create_date,112)) =convert(int,convert(char(10),dateadd(day,-1,getdate()),112)) 

//这月的企业
select *from eb_company where is_company=1 and 
convert(int,substring(convert(char(10),create_date,112),1,6))>=convert(int,substring(convert(char(10),getdate(),112),1,6))
//上月的企业
select *from eb_company where is_company=1 and 
convert(int,substring(convert(char(10),create_date,112),1,6))>=convert(int,substring(convert(char(10),dateadd(month,-1,dateadd(dd,-datepart(dd,getdate())+1,getdate())),112),1,6))
and convert(int,substring(convert(char(10),create_date,112),1,6))<convert(int,substring(convert(char(10),dateadd(month,0,dateadd(dd,-datepart(dd,getdate())+1,getdate())),112),1,6))



//获取当前月份
int month = db.CountBySQL("select  month(getdate()) ");

//根据年份与月份获取当月最后一天
int day = db.CountBySQL("select  day (dateadd(day,-1,dateadd(month,1,'" + year + "-" + month + "'+'-01')))");

0 0
原创粉丝点击