% dim daydif dim days '定义查询前后多少天内生日的同学,如60则查询前一个月后下一个月生日的同学名单。 SQL="Select name,brithday from class " Set rs=server.CreateObject("ADODB.RecordSet") rs.Open SQL,con,1,1 for i=1 to rs.recordcount '读出所有的数据 if rs.eof then exit for daydif=abs(datediff("d",date,rs("birthday")) )mod 365 if daydif days response.write rs("name")%> response.write "font color="#FF0000">" response.write rs("birthday")"、/font>" end if rs.movenext loop rs.Close Set rs=nothing %>
方法三: sql server: % If month(Now())=12 and day(now())>24 Then sSql = "select FoodID, Strname, TimeID from Tfood where ( datediff(d,getdate(),dateadd(year,datediff(Year,TimeID,GetDate()),TimeID))=200 and datediff(d,getdate(),dateadd(year,datediff(Year,TimeID,GetDate()),TimeID))>=0 ) Or ( datediff(d,getdate(),dateadd(year,datediff(Year,TimeID,GetDate())+1,TimeID))=200 and datediff(d,getdate(),dateadd(year,datediff(Year,TimeID,GetDate())+1,TimeID))>=0 )" Else sSql = "select FoodID, Strname, TimeID from Tfood where ( datediff(d,getdate(),dateadd(year,datediff(Year,TimeID,GetDate()),TimeID))=200 and datediff(d,getdate(),dateadd(year,datediff(Year,TimeID,GetDate()),TimeID))>=0 )" End If %> Access: % If month(Now())=12 and day(now())>24 Then sSql = "SELECT * FROM customers WHERE ( datediff('d',date(),dateadd('yyyy',datediff('yyyy',Birthday,date()),Birthday))=5 and datediff('d',date(),dateadd('yyyy',datediff('yyyy',Birthday,date()),Birthday))>=0 ) Or ( datediff('d',date(),dateadd('yyyy',datediff('yyyy',Birthday,date())+1,Birthday))=5 and datediff('d',date(),dateadd('yyyy',datediff('yyyy',Birthday,date())+1,Birthday))>=0 );" Else sSql = "SELECT * FROM customers WHERE (DateDiff('d',date(),DateAdd('yyyy',DateDiff('yyyy',[Birthday],date()),[Birthday]))=5 And DateDiff('d',date(),DateAdd('yyyy',DateDiff('yyyy',[Birthday],date()),[Birthday]))>=0);" End If %>