怎么样可以查到下面表单与数据库字段(日期型数据)进行查询!在线等待分不够我可以再加。。
1<option>=============</option>
1<option>最近一周</option>
1<option>最近两周</option>
1<option>最近三周</option>
1<option>最近一个月</option>
1<option>最近两个月</option>
---------------------------------------------------------------
最近一周:
strsql= "select * from 表名 where datediff(day,数据库字段,getdate())<=7 and datediff(day,数据库字段,getdate())>=0"
最近两周:
strsql= "select * from 表名 where datediff(day,数据库字段,getdate())<=14 and datediff(day,数据库字段,getdate())>=0"
最近三周:
strsql= "select * from 表名 where datediff(day,数据库字段,getdate())<=21 and datediff(day,数据库字段,getdate())>=0"
---------------------------------------------------------------
http://www.pttc.yn.cninfo.net/dtsy/asp/aspjq/59424518.htm
---------------------------------------------------------------
strsql= "select * from 表名 where datediff(day,数据库字段,getdate())<=7 and datediff(day,数据库字段,getdate())>=0"
---------------------------------------------------------------
最近1月:
strsql= "select * from 表名 where datediff(day,数据库字段,getdate())<=30 and datediff(day,数据库字段,getdate())>=0"
最近2月:
strsql= "select * from 表名 where datediff(day,数据库字段,getdate())<=60 and datediff(day,数据库字段,getdate())>=0"
---------------------------------------------------------------
或者
最近1月:
'先计算上月的天数
oneMonthdays = Datediff("d",DateAdd("m",-1,date()),date())
strsql= "select * from 表名 where datediff(day,数据库字段,getdate())<=" &oneMonthdays &"and datediff(day,数据库字段,getdate())>=0"
最近2月
'先计算上2个月的天数
twoMonthdays = Datediff("d",DateAdd("m",-2,date()),date())
strsql= "select * from 表名 where datediff(day,数据库字段,getdate())<=" &twoMonthdays &"and datediff(day,数据库字段,getdate())>=0"
---------------------------------------------------------------
好使。
我的一个程序。
判段缴费时间的。
也是将数据库字段里加入的now()跟系统时间比较的。
1<font color="#FF0000">
if trim(company.Fields.Item("moneytype").Value)="一年" then
if year(now())-year(company.Fields.Item("sdate").Value)>1 then
1过期了
end if
if year(now())-year(company.Fields.Item("sdate").Value)=1 then
if month(now())-month(company.Fields.Item("sdate").Value)>1 then
1过期了
end if
end if
end if
if trim(company.Fields.Item("moneytype").Value)="两年" then
if year(now())-year(company.Fields.Item("sdate").Value)>2 then
1过期了
end if
if year(now())-year(company.Fields.Item("sdate").Value)=2 then
if month(now())-month(company.Fields.Item("sdate").Value)>1 then
1过期了
end if
end if
end if
if trim(company.Fields.Item("moneytype").Value)="三年" then
if year(now())-year(company.Fields.Item("sdate").Value)>3 then
1过期了
end if
if year(now())-year(company.Fields.Item("sdate").Value)=3 then
if month(now())-month(company.Fields.Item("sdate").Value)>1 then
1过期了
end if
end if
end if
if trim(company.Fields.Item("moneytype").Value)="一个月" then
if year(now())-year(company.Fields.Item("sdate").Value)>1 then
1过期了
end if
if (year(now())-year(company.Fields.Item("sdate").Value))=1 then
if (month(now())+12-month(company.Fields.Item("sdate").Value)>1) then
1过期了
end if
end if
if (year(now())-year(company.Fields.Item("sdate").Value))=0 then
if (month(now())-month(company.Fields.Item("sdate").Value)>1) then
1过期了
end if
end if
end if
if trim(company.Fields.Item("moneytype").Value)="三个月" then
if year(now())-year(company.Fields.Item("sdate").Value)>1 then
1过期了
end if
if (year(now())-year(company.Fields.Item("sdate").Value))=1 then
if (month(now())+12-month(company.Fields.Item("sdate").Value)>3) then
1过期了
end if
end if
if (year(now())=year(company.Fields.Item("sdate").Value)) then
if (month(now())-month(company.Fields.Item("sdate").Value)>3) then
1过期了
end if
end if
end if
if trim(company.Fields.Item("moneytype").Value)="半年" then
if year(now())-year(company.Fields.Item("sdate").Value)>1 then
1过期了
end if
if (year(now())-year(company.Fields.Item("sdate").Value))=1 then
if (month(now())+12-month(company.Fields.Item("sdate").Value)>6) then
1过期了
end if
end if
if (year(now())=year(company.Fields.Item("sdate").Value)) then
if (month(now())-month(company.Fields.Item("sdate").Value)>6) then
1过期了
end if
end if
end if
1</font>
---------------------------------------------------------------
哦。。是Access数据库?把getdate()换为now()
---------------------------------------------------------------
-->
datediff(day,fdata,getdate())<=7
-->
datediff(day,fdata,now())<=7