标题:求段代码 asp 批量修改时间??
只看楼主
sunfeiyao
Rank: 1
等 级:新手上路
帖 子:68
专家分:0
注 册:2011-9-7
得分:0 
能不能限制从7点开始随机时间  

每当更新3个时间后 在从7点开始

2012-06-07 09:26
coretear
Rank: 4
等 级:业余侠客
威 望:1
帖 子:102
专家分:244
注 册:2012-6-5
得分:0 
程序代码:
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
lid = 1
rid = 7
Lyear = FormatDateTime(now(),2) '日期如果也加段的话自己搞吧,照葫芦画瓢
'小时 时间段 按照时间规则 24以内 最好在最好不要超过 22,因为有随机的+59秒所以可能产生日期+1天的可能
LHour = "9-20"  
'按照时间规则 60以内 最好在最好不要超过 58,因为有随机的+59秒所以可能产生日期+1天的可能
Lminute = "1-58" 

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)
    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
    Dim LLHour,LLminute
    Randomize
    LLHour = Split(LHour, "-", -1, 1)
    LLminute = Split(Lminute, "-", -1, 1)
    
    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
        ydate = GetDate(Lyear,LHour,Lminute)
        Do Until Rs.EOF
            '随机根据当前时间生成时间,加(1-59)秒随机数,可以换分钟,小时
            ydate = DATEADD ("s" , Int((59 * Rnd) + 1),ydate)
            BHour = FormatDateTime(ydate,3)
            
            AHour = Split(LHour, "-", -1, 1)
            BHour = Split(BHour, ":", -1, 1)
            
            Aminute= Split(Lminute, "-", -1, 1)
        
            LHour = BHour(0)&"-"&AHour(1)
            Lminute = BHour(1)&"-"&Aminute(1)
            '当每超过三条数据的时候判断
            If (Total Mod 3)=0 Then
                '每3条+1天
                If Total <> 0 Then
                    '重新初始化各值
                    ydate = FormatDateTime(ydate,2)&" "&LLHour(0)&":"&LLminute(0)&":00"
                    'Response.write ydate
                    ydate = DATEADD ("d" , 1, ydate)
                    Lyear = FormatDateTime(ydate,2)
                    LHour = LLHour(0)&"-"&LLHour(1)
                    Lminute = LLminute(0)&"-"&LLminute(1)
                    Total = 0
                End If
            End If
           ydate = GetDate(Lyear,LHour,Lminute)
        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


工作去了,你在自己改吧,给你都这样了你在搞不定的话,我无语,不会帮你了,等于害你了
2012-06-07 09:41
sunfeiyao
Rank: 1
等 级:新手上路
帖 子:68
专家分:0
注 册:2011-9-7
得分:0 
老师,您真好,谢谢,能留下您的QQ吗??有问题还可以请教吗??
2012-06-07 09:45



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-370881-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.065776 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved