根据id范围,根据时间段随机生成时间,每3条时间加1天
'每3条+1天 If Total <> 0 Then ydate = DATEADD ("d" , 1, ydate) Lyear = FormatDateTime(ydate,2) Total = 0 End If
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 = 1 rid = 7 Lyear = "2012-6-5" '日期如果也加段的话自己搞吧,照葫芦画瓢 LHour = "7-9" '小时 时间段 按照时间规则 24以内 Lminute = "10-50" '分钟 时间段 60以内 'lid 开始id 'rid 结束id Call SetDate(lid,rid,Lyear,LHour,Lminute) '打开数据库自己加 Function GetDate(Lyeara,LHoura,Lminutea) Dim L_Hour,LHT_Hour,LHour_l,LHour_r,LHourb Dim L_minute,LHT_minute,Lminute_l,Lminute_r,Lminuteb,Lsecondb Randomize 'Response.write LHour_r L_Hour = Split(LHoura, "-", -1, 1) LHT_Hour = L_Hour LHour_l = Int(L_Hour(1))-Int(L_Hour(0))+1 LHour_r = Int(L_Hour(0)) LHourb = Int((LHour_l * Rnd)+LHour_r) L_minute = Split(Lminutea, "-", -1, 1) LHT_minute = L_minute Lminute_l = Int(L_minute(1))-Int(L_minute(0))+1 Lminute_r = Int(L_minute(0)) Lminuteb = Int((Lminute_l * Rnd)+Lminute_r) Lsecondb = Int((59 * Rnd) + 1) 'Response.write "<font color=red>"&Lyeara&" "&LHourb&":"&Lminuteb&":"&Lsecondb&"</font>" GetDate = FormatDateTime(Lyeara&" "&LHourb&":"&Lminuteb&":"&Lsecondb) Response.write "<br><font color=red>时间段:"&FormatDateTime(Lyear&" "&LHT_Hour(0)&":"&LHT_minute(0)&":00")&"至"&FormatDateTime(Lyear&" "&LHT_Hour(1)&":"&LHT_minute(1)&":00")&"</font>" End Function Function SetDate(lid,rid,Lyear,LHour,Lminute) Dim Sql,Rs,Total,ydate Randomize Set Rs = Server.Createobject("adodb.recordset") Total = 0 Sql = "select id,ydate from Table_1 where id >= "&lid&" and id <= "&rid 'Response.write sql Rs.Open Sql,Conn,1,1 If Rs.Bof Or Rs.Eof Then 'Response.write "False" Else Do Until Rs.EOF ydate = GetDate(Lyear,LHour,Lminute) '当每超过三条数据的时候判断 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) Lyear = FormatDateTime(ydate,2) Total = 0 End If Else '随机根据当前时间生成时间 ydate = DATEADD ("s" ,Int((1000 * Rnd) + 1), ydate) End If Response.write "<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