Hotel Room Rates for different seasons

前端 未结 4 1722
南方客
南方客 2020-12-17 06:56

I have a database (MySQL) with a table containing date ranges (as startdate and enddate) and a rate field. The date range implies different seasons (low, high etc.). The sce

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-17 07:19

    Disclaimer: This is not the most efficient one, but it's the more clear, and if you have the price list cached in an array, the performance hit will be meaningless.

    Dim numberOfDays As Integer, i As Integer
    Dim CheckInDate As Date, CheckOutDate As Date, CurrDate As Date
    Dim TotalRate As Currency
    TotalRate = 0
    CheckInDate = DateSerial(2007, 4, 29)
    CheckOutDate = DateSerial(2007, 5, 3)
    ''// -1 asumming the last day is checkout day
    numberOfDays = DateDiff("d", CheckInDate, CheckOutDate) - 1 
    For i = 0 To numberOfDays
       CurrDate = DateAdd("d", i, CheckInDate)
       TotalRate = TotalRate + CalculateRateForDay(CurrDate)
    Next
    

提交回复
热议问题