[Fixed]-Where and how to calculate total price depending on date range user selected?

1👍

It doesn’t have anything to do with django but rather python. I assume user_start_date and user_end_date are both python datetime.date or datetime.datetime objects, then you could do:

num_days = (user_end_date - user_start_date).days
total_price = num_days * 20

0👍

https://docs.python.org/2/library/calendar.html

A calendar is necessary as you should be aware that not all months have the same amount of days in them. itermonthdates(year, month) returns an iterator for all days in the month. Run through that iterator and increment a count for every date match within the range. Of course if the end date extends into the next month keep the same counter.

👤ARoss

Leave a comment