判断日期连续的数据

rongguo52013 2011-09-21 03:03:26
数据库中有这样的一种数据,在网页中添加数据,添加某人的姓名和日期,添加一次算一次旷工,如果如果旷工一天则颜色不变,如果旷工两天则显示红色,如果旷工三天怎显示绿色,如果旷工三天以上则显示黄色,要怎样编写。
姓名 旷工日期
张三 2011-9-14
张三 2011-9-15
张三 2011-9-16
李四 2011-9-10
李四 2011-9-12
李四 2011-9-14
张三 2011-9-20
...全文
146 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
shupo 2011-09-22
  • 打赏
  • 举报
回复
连续的日期才判断
黑心 2011-09-22
  • 打赏
  • 举报
回复
不是告诉过你了吗。稍微变一下就可以了。
response.Write "<table border=1>"
sql="select * from utable order by username,date "
set rs=server.CreateObject("adodb.recordset")
rs.open sql,conn,1,3

do while not rs.eof
response.Write "<tr>"
response.Write "<td>"&rs("ID")&"</td><td>"&rs("username")&"</td><td bgcolor='"&sub_utable(rs("username"),rs("date"))&"'>"&rs("date")&"</td>"
response.Write "</tr>"
rs.movenext
loop

response.Write "</table>"
function sub_utable(us,da)
flag=0
sub_utable=""
sql1="select * from utable where username='"&us&"' and datediff('d','"&da&"',[date])=3 order by date "
set rs1=server.CreateObject("adodb.recordset")
rs1.open sql1,conn,1,1
if rs1.recordcount>0 then flag=flag+1 else flag=0
rs1.close:set rs1=nothing
sql1="select * from utable where username='"&us&"' and datediff('d','"&da&"',[date])=2 order by date "
set rs1=server.CreateObject("adodb.recordset")
rs1.open sql1,conn,1,1
if rs1.recordcount>0 then flag=flag+1 else flag=0
rs1.close:set rs1=nothing
sql1="select * from utable where username='"&us&"' and datediff('d','"&da&"',[date])=1 order by date "
set rs1=server.CreateObject("adodb.recordset")
rs1.open sql1,conn,1,1
if rs1.recordcount>0 then flag=flag+1 else flag=0
rs1.close:set rs1=nothing
if flag>=1 then sub_utable="red"
if flag>=2 then sub_utable="green"
if flag>=3 then sub_utable="yellow":exit function
sql1="select * from utable where username='"&us&"' and datediff('d','"&da&"',[date])=-1 order by date "
set rs1=server.CreateObject("adodb.recordset")
rs1.open sql1,conn,1,1
if rs1.recordcount>0 then flag=flag+1 else flag=0
rs1.close:set rs1=nothing
if flag>=1 then sub_utable="red"
if flag>=2 then sub_utable="green"
if flag>=3 then sub_utable="yellow":exit function
sql1="select * from utable where username='"&us&"' and datediff('d','"&da&"',[date])=-2 order by date "
set rs1=server.CreateObject("adodb.recordset")
rs1.open sql1,conn,1,1
if rs1.recordcount>0 then flag=flag+1 else flag=0
rs1.close:set rs1=nothing
if flag>=2 then sub_utable="green"
if flag>=3 then sub_utable="yellow":exit function
sql1="select * from utable where username='"&us&"' and datediff('d','"&da&"',[date])=-3 order by date "
set rs1=server.CreateObject("adodb.recordset")
rs1.open sql1,conn,1,1
if rs1.recordcount>0 then flag=flag+1 else flag=0
rs1.close:set rs1=nothing
if flag>=3 then sub_utable="yellow":exit function
end function
rongguo52013 2011-09-22
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 myshachong 的回复:]
试试用 DateDiff 函数

比如这样,

set rs=server.createobject("adodb.recordset")
sql= "SELECT * from 你的姓名字段 WHERE 你的姓名字段 =姓名 "
rs.open sql,conn,1,1

自己想办法记录两条记录,上一次 a 下一条 b

a="2011-9-20"
b="2011-9-……
[/Quote]

是连续的日期才判断
rongguo52013 2011-09-22
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 calmcrime 的回复:]
神马情况?

李四 2011-9-10
李四 2011-9-12
李四 2011-9-14


比如这个,就算李四同志 旷工一天? 因为没连续?
[/Quote]
没有连续则不用标上颜色,显示是按时间和姓名排序的,只有连续的加颜色。
myshachong 2011-09-21
  • 打赏
  • 举报
回复
试试用 DateDiff 函数

比如这样,

set rs=server.createobject("adodb.recordset")
sql= "SELECT * from 你的姓名字段 WHERE 你的姓名字段 =姓名 "
rs.open sql,conn,1,1

自己想办法记录两条记录,上一次 a 下一条 b

a="2011-9-20"
b="2011-9-22"

if DateDiff("d", a,b )> 1 then
' 显示旷工一天
end if

if DateDiff("d", a,b )> 2 then
' 显示 连续旷工2天
end if

if DateDiff("d", a,b )> 3 then
' 显示 连续旷工3天
end if


不想用if then 就用 select case
001007009 2011-09-21
  • 打赏
  • 举报
回复
神马情况?

李四 2011-9-10
李四 2011-9-12
李四 2011-9-14


比如这个,就算李四同志 旷工一天? 因为没连续?
rongguo52013 2011-09-21
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 hefeng_aspnet 的回复:]
使用 select case rs.recordcount
case 1
输出你的内容
case 2
输出内容为红色
case 3
输出内容为黄色
end select
[/Quote]

要求是连续的旷工
rongguo52013 2011-09-21
  • 打赏
  • 举报
回复
数据库中有这样的一种数据,在网页中添加数据,添加某人的姓名和日期,添加一次算一次旷工,如果如果旷工一天则颜色不变,如果连续旷工两天则显示红色,如果连续旷工三天怎显示绿色,如果连续旷工三天以上则显示黄色,要怎样编写。
姓名 旷工日期
张三 2011-9-14
张三 2011-9-15
张三 2011-9-16
李四 2011-9-10
李四 2011-9-12
李四 2011-9-14
张三 2011-9-20
csdn_aspnet 2011-09-21
  • 打赏
  • 举报
回复
使用 select case rs.recordcount
case 1
输出你的内容
case 2
输出内容为红色
case 3
输出内容为黄色
end select

001007009 2011-09-21
  • 打赏
  • 举报
回复
根据记录的次数来判断,
select case rs.recordcount
case 2
case 3
end select

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧