在写SQR时遇到的一个问题
<DIV>已知Begin_Dt和End_Dt,怎样去计算这段时间Cover了几次12:00和18:00呢?</DIV><DIV>Example: </DIV>
<DIV>1)Begin_Dt='2007-10-25 18:01'; End_Dt=''2007-10-25 20:30' </DIV>
<DIV> 则Cover_Number=0</DIV>
<DIV>2)Begin_Dt='2007-10-29 18:00'; End_Dt=''2007-10-29 20:30' </DIV>
<DIV> 则Cover_Number=1</DIV>
<DIV>3)Begin_Dt='2007-11-03 11:00'; End_Dt=''2007-11-04 19:20' </DIV>
<DIV> 则Cover_Number=4</DIV> 借鉴别人的,但还是不能太明白道理(#HourDiff=(#BeginHrs-#EndHrs)化为小时数)
Cover_12and18_By_DateTime(#BeginHrs,#EndHrs,#HourDiff,:#Count)
let #Count=0
if #BeginHrs<=12 and #BeginHrs+#HourDiff>=12
add 1 to #Count
end-if
if #BeginHrs<=18 and #BeginHrs+#HourDiff>=18
add 1 to #Count
end-if
let #TempHrs=(#HourDiff+#BeginHrs-12)/24
let #i=0
while #i<=#TempHrs
if #TempHrs>=1
add 1 to #Count
end-if
add 1 to #i
let #TempHrs = #TempHrs-1
end-while
let #TempHrs= (#HourDiff+#BeginHrs-18)/24
let #j=0
while #j<=#TempHrs
if #TempHrs>=1
add 1 to #Count
end-if
add 1 to #j
let #TempHrs=#TempHrs-1
end-while
Cover_12and18_By_DateTime
注:#BeginHrs,#EndHrs分是Begin_Dt和End_Dt的开始时数。
如:Begin_Dt='2007-10-25 18:01'; End_Dt=''2007-10-25 20:30'
则:#BeginHrs=18;#EndHrs=20.5
页:
[1]