这样吧 你列一个数据表 原数据 跟 新数据 我用asp给你 做个参考
'lid 开始id 'rid 结束id 'ldate 开始时间 'rdate 结束时间 Call SetDate(1,7,"2012-6-5 16:12:30","2012-6-5 22:12:32") '打开数据库自己加 Function SetDate(lid,rid,ldate,rdate) Dim Sql,Rs,Total,ydate Set Rs = Server.Createobject("adodb.recordset") Total = 0 ydate = Now()'可指定固定时间 Sql = "select id from Table_1 where id >= "&lid&" and id <= "&rid&" and DateDiff(s,ydate,'"&ldate&"') < 0 And DateDiff(s,ydate,'"&rdate&"') > 0" Rs.Open Sql,Conn,1,1 If Rs.Bof Or Rs.Eof Then SetDate = "False" Else Do Until Rs.EOF '当每超过三条数据的时候判断 If (Total Mod 3)=0 Then '随机根据当前时间生成时间,加(1-1000)秒随机数,可以换分钟,小时 ydate = DATEADD ("s" , Int((1000 * Rnd) + 1),ydate) '每3条+1天 If Total <> 0 Then ydate = DATEADD ("d" , 1, ydate) Total = 0 End If Else '随机根据当前时间生成时间 ydate = DATEADD ("s" ,Int((1000 * Rnd) + 1), ydate) End If Response.write "<br><br>ID:"&Rs("id")&" 更新时间:"&ydate&"<br>" Sql = "Update Table_1 Set ydate='"&ydate&"' Where id="&Rs("id") Response.write Sql Conn.Execute(Sql) Total=Total+1 Rs.MoveNext Loop End If Rs.Close Set Rs = Nothing SetDate = "True" End Function '关闭数据库自己加
Dim Db,Conn Db = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("01.mdb") Set Conn = Server.CreateObject("ADODB.Connection") Conn.open Db 'lid 开始id 'rid 结束id 'ldate 开始时间 'rdate 结束时间 Call SetDate(1,7,"2012-6-5 16:12:30","2012-6-5 22:12:32") '打开数据库自己加 Function SetDate(lid,rid,ldate,rdate) Dim Sql,Rs,Total,ydate Set Rs = Server.Createobject("adodb.recordset") Total = 0 ydate = Now()'可指定固定时间 Sql = "select id,ydate from Table_1 where id >= "&lid&" and id <= "&rid&" and DateDiff(""s"",ydate,'"&ldate&"') < 0 And DateDiff(""s"",ydate,'"&rdate&"') > 0" 'Response.write sql Rs.Open Sql,Conn,1,1 If Rs.Bof Or Rs.Eof Then Response.write "False" Else Do Until Rs.EOF '当每超过三条数据的时候判断 If (Total Mod 3)=0 Then '随机根据当前时间生成时间,加(1-1000)秒随机数,可以换分钟,小时 ydate = DATEADD ("s" , Int((1000 * Rnd) + 1),ydate) '每3条+1天 If Total <> 0 Then ydate = DATEADD ("d" , 1, ydate) Total = 0 End If Else '随机根据当前时间生成时间 ydate = DATEADD ("s" ,Int((1000 * Rnd) + 1), ydate) End If Response.write "<br><br>ID:"&Rs("id")&" 更新时间:"&ydate&"<br>" Sql = "Update Table_1 Set ydate='"&ydate&"' Where id="&Rs("id") Response.write Sql Conn.Execute(Sql) Total=Total+1 Rs.MoveNext Loop End If Rs.Close Set Rs = Nothing Response.write "True" End Function '关闭数据库自己加 Conn.Close Set Conn = Nothing