Vbscript ASP-分为小时
我从分钟算小时Vbscript ASP-分为小时,vbscript,asp-classic,datediff,Vbscript,Asp Classic,Datediff,我从分钟算小时 <% hrs =(DateDiff("N", cdate(m1), CDate(m2) ))/60 %> . 。 它没有给出预期的输出 我需要这个小时来产生工资 所以时间小时应该是7.25,7.50,7.75等等。。。不是7.23或7.28、7.30 有时它给出7.833333 请帮助使用 100Minutes = 100 * 60Minutes \ 60 从“正常”分钟计算厘米分钟。演示: Dim dtStart : dtStart = #11/5/2
<% hrs =(DateDiff("N", cdate(m1), CDate(m2) ))/60 %> .
。
它没有给出预期的输出
我需要这个小时来产生工资
所以时间小时应该是7.25,7.50,7.75等等。。。不是7.23或7.28、7.30
有时它给出7.833333
请帮助使用
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
使用
从“正常”分钟计算厘米分钟。演示:
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
我猜你真正想要的是:-
Dim hrs
hrs = Int(DateDiff("N", CDate(m1), CDate(m2)) / 15) / 4
这是基于你只根据每季度一小时的工作时间来支付工资。我猜你真正想要的是:-
Dim hrs
hrs = Int(DateDiff("N", CDate(m1), CDate(m2)) / 15) / 4
这是基于你只根据每季度一小时的工作时间来支付工资。安东尼的解决方案非常棒,但它是四舍五入的。如果您想将超过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的值更改为您认为合适的任何值。安东尼的解决方案非常棒,但它可以进行四舍五入。如果您想将超过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的值更改为您认为合适的任何值。您的规范非常弱。你的意思是你只希望以15分钟为增量生成hr值吗?如果是,需要什么舍入政策?你想四舍五入到最接近的整整四分之一小时吗?你的规格太低了。你的意思是你只希望以15分钟为增量生成hr值吗?如果是,需要什么舍入政策?你想四舍五入到最近的整整四分之一小时吗?谢谢,差不多是我所需要的。谢谢,几乎是我需要的。