What programming strategy can be used, find apptox total rental price

What programming strategy can be used, to find aporox rental total prixe,…the most efficient
Given date intervals and a rental price, this interval Not by month but arbitrary: eg 13-04-2017 till 17-05-2017 50$/day

Find the total rental cost, may a rental go to two even three intervals…
Prices are for last 2yrs
Mysql, php, js, jQuery

Find approx cost total with js client side I think is preferred, what you think?

You can do all of this client side as follows:
1: Create a rates table showing day rates for various date ranges as applicable.

rates[rates.length]={startDate:“2014,06,20”, endDate:“2014,09,29”, perDayDol:50};
rates[rates.length]={startDate:“2014,09,30”, endDate:“2015,01,12”, perDayDol:52};
rates[rates.length]={startDate:“2015,01,13”,endDate:“2015,04,22”, perDayDol:55};

2: Dynamically build a table of dates and their millisecond equivalents for the dates shown in the rates table. A small sample is shown below for the rental range 22 June 2014 to 2 July 2014

20 Jun 2014 msec= 1403186400000 dayRate= 50 dayRateTotal= 0
21 Jun 2014 msec= 1403272800000 dayRate= 50 dayRateTotal= 0
22 Jun 2014 msec= 1403359200000 dayRate= 50 dayRateTotal= 50
23 Jun 2014 msec= 1403445600000 dayRate= 50 dayRateTotal= 100
24 Jun 2014 msec= 1403532000000 dayRate= 50 dayRateTotal= 150
25 Jun 2014 msec= 1403618400000 dayRate= 50 dayRateTotal= 200
26 Jun 2014 msec= 1403704800000 dayRate= 50 dayRateTotal= 250
27 Jun 2014 msec= 1403791200000 dayRate= 50 dayRateTotal= 300
28 Jun 2014 msec= 1403877600000 dayRate= 50 dayRateTotal= 350
29 Jun 2014 msec= 1403964000000 dayRate= 50 dayRateTotal= 400
30 Jun 2014 msec= 1404050400000 dayRate= 50 dayRateTotal= 450
01 Jul 2014 msec= 1404136800000 dayRate= 50 dayRateTotal= 500
02 Jul 2014 msec= 1404223200000 dayRate= 50 dayRateTotal= 550
03 Jul 2014 msec= 1404309600000 dayRate= 50 dayRateTotal= 0

3: Extract the last entry as the total required. ($550)

While the test example prints out the millisecond table, when the script is used within another program, printing is not necessary, and the result is still available…

IE and Firefox have a problem with the syntax new Date(“2016, 4, 23”). To avoid this the example creates an empty date object and then sets the dates using standard javascript setDate, setMonth, setYear. Using this method allows the program to run in all browsers back to IE7.

A working example on JSFiddle of the program can be found HERE.

Please use valid dates and stay within the test data range as there is no error checking for this example.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.