我从分钟开始计算小时数。
<% hrs =(DateDiff("N", cdate(m1), CDate(m2) ))/60 %> .它没有给出预期的输出。
我需要这个小时来产生工资,所以时间小时应该像这个7.25,7.50,7.75和...不是7.23或7.28,而是7.30,有时它会给7.833333333333
请帮帮忙
发布于 2011-11-06 01:27:20
我猜你真正想要的是:
Dim hrs
hrs = Int(DateDiff("N", CDate(m1), CDate(m2)) / 15) / 4这是基于你只根据工作时间支付工资,以一刻钟为增量。
发布于 2011-11-07 01:01:22
安东尼的解决方案很棒,但它会四舍五入。如果您想要在7分钟内四舍五入到最接近的15分钟,则使用以下命令:
Const csRoundUp = 7
Dim Minutes
Dim hrs
Minutes = Int(DateDiff("N", CDate(Date1), CDate(Date2)) Mod 60)
if Minutes > csRoundUp then
hrs = (Int(DateDiff("N", CDate(Date1), CDate(Date2)) / 15)+1) / 4
else
hrs = Int(DateDiff("N", CDate(Date1), CDate(Date2)) / 15) / 4
end if当然,您可以将csRoundUp的值更改为您认为合适的任何值。
发布于 2011-11-05 16:25:28
使用
100Minutes = 100 * 60Minutes \ 60从“正常”分钟计算出百分制分钟。演示:
Dim dtStart : dtStart = #11/5/2011 08:00:00#
Dim aTests : aTests = Array( _
0, 1, 6, 15, 30, 45, 59, 60, 90 _
)
Dim nAddMins
For Each nAddMins In aTests
Dim dtStop : dtStop = DateAdd( "n", 7 * 60 + nAddMins, dtStart )
Dim dtDiff : dtDiff = CDate( dtStop - dtStart )
Dim nHours : nHours = Hour( dtDiff )
Dim nMins : nMins = Minute( dtDiff )
If nAddMins Mod 60 <> nMins Then
Err.Raise vbObjectError + 4711, "CentiMinute", nAddMins & " <> " & nMins
End If
Dim nCMins : nCMins = 100 * nMins \ 60
WScript.Echo dtStart, dtStop _
, Right( 1000 + nAddMins, 3 ) _
, Right( 100 + nHours , 2 ) & ":" & Right( 100 + nMins , 2 ) _
, Right( 100 + nHours , 2 ) & "." & Right( 100 + nCMins , 2 )
Next输出(德语区域设置):
=========================================================
05.11.2011 08:00:00 05.11.2011 15:00:00 000 07:00 07.00
05.11.2011 08:00:00 05.11.2011 15:01:00 001 07:01 07.01
05.11.2011 08:00:00 05.11.2011 15:06:00 006 07:06 07.10
05.11.2011 08:00:00 05.11.2011 15:15:00 015 07:15 07.25
05.11.2011 08:00:00 05.11.2011 15:30:00 030 07:30 07.50
05.11.2011 08:00:00 05.11.2011 15:45:00 045 07:45 07.75
05.11.2011 08:00:00 05.11.2011 15:59:00 059 07:59 07.98
05.11.2011 08:00:00 05.11.2011 16:00:00 060 08:00 08.00
05.11.2011 08:00:00 05.11.2011 16:30:00 090 08:30 08.50
=========================================================https://stackoverflow.com/questions/8017949
复制相似问题