I am having a bit of trouble with an application I am working on and I hope to get some guidance.
I have a simple booking system: each item has a standard price, but there are some periods when the price can change.
For example:
Standard price is 100/day
From
Oct. 1st
toFeb. 1st
of each year, the price is 80/dayFrom
Jun. 1st
toAug. 31st
of each year the price is 120/day[...] up to 6 different price changes (seasons)
Because this is a yearly occurrence, I only need the month and day, but I dont't know how to store these values in the database. I was thinking of having two fields, one for month and one for day which hold numeric values(01-12
for month, 01-31
for day). These values are set by the user himself and they are relative to the item itself, it's not fixed for everyone.
The problem is that when someone makes a booking, I need to check if the price needs to be changed and I don't understand how to build the query to check this. To make maters worst, the price can have multiple values for a booked period.
Following the example above, If I were to book an item from Sep. 1st (current year)
to Jul. 1st (next year)
, the price will be as follow:
100/day from
Sep. 1st
toSep. 30th
80/day from
Oct. 1st
toFeb. 1st
100/day from
Feb. 2nd
to May 31st
120/day from
Jun. 1st
toJul. 1st
Is there any way of checking these cases without having to loop each day and checking against the database for a match ?
Thank you