返回列表 回复 发帖

在写SQR时遇到的一个问题

已知Begin_Dt和End_Dt,怎样去计算这段时间Cover了几次12:00和18:00呢?
Example:
1)Begin_Dt='2007-10-25 18:01';   End_Dt=''2007-10-25 20:30' 
  则Cover_Number=0
2)Begin_Dt='2007-10-29 18:00';   End_Dt=''2007-10-29 20:30' 
  则Cover_Number=1
3)Begin_Dt='2007-11-03 11:00';   End_Dt=''2007-11-04 19:20' 
  则Cover_Number=4
今天的努力是为了明天的生活
所以
我必须忍耐
*************************************
热烈欢迎大家来我的地盘踩踩⌒_⌒
http://lovexue.erp100.com
借鉴别人的,但还是不能太明白道理(#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
返回列表