Erp100论坛's Archiver

gxgxue 发表于 2008-1-25 16:41

在写SQR时遇到的一个问题

<DIV>已知Begin_Dt和End_Dt,怎样去计算这段时间Cover了几次12:00和18:00呢?</DIV>
<DIV>Example: </DIV>
<DIV>1)Begin_Dt='2007-10-25 18:01';&nbsp;&nbsp; End_Dt=''2007-10-25 20:30'&nbsp; </DIV>
<DIV>&nbsp; 则Cover_Number=0</DIV>
<DIV>2)Begin_Dt='2007-10-29 18:00';&nbsp;&nbsp; End_Dt=''2007-10-29 20:30'&nbsp; </DIV>
<DIV>&nbsp; 则Cover_Number=1</DIV>
<DIV>3)Begin_Dt='2007-11-03 11:00';&nbsp;&nbsp; End_Dt=''2007-11-04 19:20'&nbsp; </DIV>
<DIV>&nbsp; 则Cover_Number=4</DIV>

gxgxue 发表于 2008-1-25 16:45

借鉴别人的,但还是不能太明白道理(#HourDiff=(#BeginHrs-#EndHrs)化为小时数)

Cover_12and18_By_DateTime(#BeginHrs,#EndHrs,#HourDiff,:#Count)
let #Count=0
if #BeginHrs&lt;=12 and #BeginHrs+#HourDiff&gt;=12
   add 1 to #Count
end-if
if #BeginHrs&lt;=18 and #BeginHrs+#HourDiff&gt;=18
   add 1 to #Count
end-if
let #TempHrs=(#HourDiff+#BeginHrs-12)/24
let #i=0
while #i&lt;=#TempHrs
  if #TempHrs&gt;=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&lt;=#TempHrs
  if #TempHrs&gt;=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]

Powered by Discuz! Archiver 7.0.0  © 2001-2007 Comsenz Inc.