在窗体上放一个List1,Private Sub Form_Load()
    Dim d As Date
    Dim i As Integer
    d = "2001-08-22 03:00:00"
    For i = 1 To 30
        d = DateAdd("h", 1, d)
        List1.AddItem d
    Next i
End Sub
看看是不是你想要的

解决方案 »

  1.   

    Public Function GetEndTime(StartTime As Date, WorkingHours As Integer) As Date
    Const StartTimePerDay = "00:00:00"
    Const EndTimePerDay = "20:00:00"Dim HoursPerDay As Integer, StartDate As Date, tmp As Integer
    HoursPerDay = DateDiff("H", StartTimePerDay, EndTimePerDay)
    StartDate = CDate(Format(StartTime, "DD-MMM-YYYY"))
    StartTime = CDate(Format(StartTime, "HH:MM:SS"))tmp = DateDiff("H", StartTime, EndTimePerDay)
    If WorkingHours <= tmp Then
        GetEndTime = StartDate + StartTime + WorkingHours / 24
    Else
        StartDate = StartDate + 1 + Int((WorkingHours - tmp) / HoursPerDay)
        StartTime = CDate(StartTimePerDay) + (((WorkingHours - tmp) Mod HoursPerDay) / 24)
        GetEndTime = StartDate + StartTime
    End IfEnd Function
    test result:
    ?getendtime("2001-08-20 13:00:00",30)
    8/22/01 3:00:00 AM 
      

  2.   

    不是,我想要一个算法
    Exp("2001-08-22 03:00:00",30)="2001-08-03 03:00:00"
    关键问题是Exp是什么?
      

  3.   

    'the result is same
    'it seems to be much understandable to use function 'DATEADD'
    'pls try again
    Public Function GetEndTime(StartTime As Date, WorkingHours As Integer) As Date
    Const StartTimePerDay = "00:00:00"
    Const EndTimePerDay = "20:00:00"Dim HoursPerDay As Integer, StartDate As Date, tmp As Integer
    HoursPerDay = DateDiff("H", StartTimePerDay, EndTimePerDay)
    StartDate = CDate(Format(StartTime, "DD-MMM-YYYY"))
    StartTime = CDate(Format(StartTime, "HH:MM:SS"))tmp = DateDiff("H", StartTime, EndTimePerDay)
    If WorkingHours <= tmp Then
        GetEndTime = DateAdd("h", WorkingHours, StartDate + StartTime)
    Else
        StartDate = StartDate + 1 + Int((WorkingHours - tmp) / HoursPerDay)
        StartTime = DateAdd("h", (WorkingHours - tmp) Mod HoursPerDay, CDate(StartTimePerDay))
        GetEndTime = StartDate + StartTime
    End IfEnd Function
      

  4.   

    对了,哈哈!!
    看看我写的,在SQL StoreProcedure里面
    CREATE PROCEDURE Calc_Time
    @InBegin as datetime, --开始时间
    @InHour as numeric(9,1), --小时数
    @OutEnd as datetime output --结束时间
    ASdeclare @Hour1 as numeric(9,1) --当天尚余的工时
    declare @Hour2 as numeric(9,1) --计算整除20余下的工时
    declare @IDay  as int
    declare @Temp  as datetimeselect @Hour1=datediff(mi,right(@InBegin,8),'20:00:00')/60
    if @InHour<@Hour1 --超出当天,按照每天20小时计算
    select @OutEnd=dateadd(hh,@InHour,@InBegin)
    else
    begin
    select @Temp=dateadd(hh,@Hour1+4,@InBegin)
    select @IDay=(@InHour-@Hour1)/20
    select @Temp=dateadd(dd,@IDay,@Temp)
    select @Hour2= (@InHour-@Hour1)-@IDay*20
    select @OutEnd=dateadd(hh,@Hour2,@Temp)
    end