对了,哈哈!!
看看我写的,在SQL StoreProcedure里面
CREATE PROCEDURE Calc_Time
@InBegin as datetime, --开始时间
@InHour as numeric(9,1), --小时数
@OutEnd as datetime output --结束时间
AS
declare @Hour1 as numeric(9,1) --当天尚余的工时
declare @Hour2 as numeric(9,1) --计算整除20余下的工时
declare @IDay as int
declare @Temp as datetime
select @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
'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 If
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
看看是不是你想要的