代码问题,目前的代码是当天的新文章发表后,能在文章标题后显示new.gif图片。 想改成当天的新文章后仍显示new.gif图片,但昨天的新文章后显示new1.gif图片。 求高手指点,代码如下。 '显示主页栏目内容 Sub Disp_subject(subject_no,disp_count,title_len,href_link,c_images,c_images_w,c_images_h) dim i,href_url,have_image,cur_title_len,send_time,c_mon,c_day,disp_date,sql,rs,a_title,cur_disp_title sql="select id,title,main_image,send_time from "& application("subject_table")(subject_no,2) &" where enable_flag='1' order by send_time desc" set rs=conn.execute(sql) for i=1 to disp_count if rs.eof then response.write "<table><TR><TD align=left valign=top class=fontmidtitle height=20></TD></TR></table>" else cur_title_len=title_len have_image=0 if not isnull(rs("main_image").value) and rs("main_image").value<>"" then have_image=1 cur_title_len=cur_title_len-1 end if if not isnull(rs("send_time").value) then send_time=cdate(formatdatetime(rs("send_time").value,2)) c_year=cstr(year(send_time)) c_mon="0"& cstr(month(send_time)) c_day="0"& cstr(day(send_time)) disp_date="("&right(c_year,0)&""& right(c_mon,2) &"-"& right(c_day,2) if have_image=1 then disp_date=disp_date &" 图)" else disp_date=disp_date &")" end if else disp_date="" send_time="" end if if send_time=date() then cur_title_len=cur_title_len-3 end if href_url=href_link &"?subject_no="& subject_no &"&id="& rs("id") a_title="" cur_disp_title=disp_title(rs("title"),cur_title_len) if cur_disp_title<>rs("title").value then a_title="title='"& rs("title") &"'" end if response.write "<table width='96%' height=25 border='0' cellspacing='0' cellpadding='0'><TR><TD align=left valign=top class=fontmidtitle height=18><IMG width="& c_images_w &" height="& c_images_h &" src='images/"& c_images &"' align=absMiddle vspace=6> <A class=fontmidtitle "& a_title &" target=_blank href='"& href_url &"'>"& cur_disp_title &"</A> "& disp_date if send_time=date() then response.write "<IMG height=11 src='images/new.gif' width=28 border=0>" end if response.write "</TD></TR></table>" rs.movenext end if next for j=i to disp_count response.write "<TR><TD align=left valign=top class=fontmidtitle height=20></TD></TR>" next set rs=nothing End Sub
改为 代码: dim DiffADate DiffADate=DateDiff("d", date(),send_time) if DiffADate=0 then response.write "<IMG height=11 src='images/new.gif' width=28 border=0>" elseif DiffADate=1 then response.write "<IMG height=11 src='images/new1.gif' width=28 border=0>" end if 试试
当然你可以用更简单的方法。。 代码: if send_time=date() then response.write "<IMG height=11 src='images/new.gif' width=28 border=0>" else response.write "<IMG height=11 src='images/new1.gif' width=28 border=0>" end if
谢谢楼主提供思路,我改好了。代码如下: If DateDiff( "d",send_time,Now)<1 Then response.write "<IMG height=11 src='images/new.gif' width=28 border=0>" elseif DateDiff( "d",send_time,Now)=1 Then response.write "<IMG height=11 src='images/new1.gif' width=28 border=0>" elseif DateDiff( "d",send_time,Now)=2 Then response.write "<IMG height=11 src='images/new2.gif' width=28 border=0>" end if