473,396 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

mysql date within season

Hi,

I am looking for general help here. I dont know how to start at this... maybe someone can point me in the right direction.

I need to calculate how many nights of a given time frame (variable dates) lie within certain ranges of times given to calcutate pricing for a hotel which has different prices depending on the season. (fixed dates).

So I have this table (MYSQL) which for example says:

from : to : price/night
01/01 : 03/31 : 100,-
04/01 : 12/20 : 120,-
12/21 : 12/31 : 160,-

How do I tackle (or at least attack) the problem to calculate the price of a stay in this hotel for, lets say Dec. 18th to Jan. 5th???

Obviously the dates which fix the pricing do not have/need the attribute (year) as they are always the same...

php boards have given me this advice
->
you could use the MySQL functions "DAY", "MONTH" to calculate whether that day of the month is in between two dates. You'd just have to give the date fields in the table a year (can be arbitrary, but pick a leap-year just-in-case; say 2000).
->

but I do not know how to put this into praxis...
Any help greatly appreciated.

THX
Dennis
(from sunny Tenerife island)
Mar 20 '08 #1
5 3617
amitpatel66
2,367 Expert 2GB
Try This:

Expand|Select|Wrap|Line Numbers
  1. SELECT SUM(price) FROM hotel_info WHERE DATE_FORMAT(from, '%m/%d') >= '12/18' AND DATE_FORMAT(to,'%m/%d') <= '01/05'
  2.  
Mar 20 '08 #2
Thanks,

this is certainly going in the right direction.
Now I played around a little, simplified the time frame and with
Expand|Select|Wrap|Line Numbers
  1. SELECT price
  2. FROM test
  3. WHERE DATE_FORMAT( FROM, '%m/%d' ) >= '02/02'
  4. AND DATE_FORMAT( TO, '%m/%d' ) <= '02/05'
  5.  
returns only one row which is correct, (there is only one row for the whole season which has one price...) and I figure thats why SUM is not doing anything here.

So now I still need to find out how many days are within one season and how many seasons are affected by my initial travel dates...

Any more help welcome
Looks as if this was not trivial.

Dennis
Mar 20 '08 #3
ronverdonk
4,258 Expert 4TB
Pity you don't have the year because that complicates it. How about handling leap years, ie. feb having 29 days. And the number of days from dec 15 to jan 25? The latter wil always cost extra calculations because you have to 'invent' the year for functions like DIFFDATE() etc.

Ronald
Mar 20 '08 #4
Hi,

thanks for all thoughts on this, greatly appreciated.

Well, of course I have the year of the client booking.
But when I get the rates information from the hotel they give them to me without a year as they are repeated every year...

So what good would it do if i store prices for 2008 and get inquiries for 2009?

Dennis
Mar 20 '08 #5
ronverdonk
4,258 Expert 4TB
That was not my remark. I asked about leap year handling and 'over-the-year' bookings.

Ronald
Mar 20 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Daniel Glenfield | last post by:
Hi, I'd like to create a website with a MySQL database to store soccer players details like goals scroed for the season. I want to use it to update my fantasy soccer team through this season, does...
1
by: Ben | last post by:
I would like to order the results from a query in a non standard way. I would like to order them by a field called season and return the results in the order LOW, MID, HIGH. I obviously can't...
3
by: David Thomas | last post by:
Hi, I've written a simple script to test the current date and perform an action depending on the result. The problem is, the date displays correctly as a complete date in an alert box but when I...
8
by: Johannes A. Brunner | last post by:
Got a simple problem. I code some site and because Im a freak I made my own session-handling. When a user open up my site it will check if there is a ssid in the url if not generate one. this will...
3
by: Lloyd Stevens | last post by:
TABLES CustomerTable CustomerTarrifTable TarrifTable WarrantTable CustomerID(P) CustomerTarrifID(P) TarrifNo(P) WarrantID(P) BoatType QuantityPurchased ProductName WarrantDate...
0
by: Takeadoe | last post by:
First, let me say that I'm brand new to Access, so please assume I know nothing. I've got a table (210k records) of deer harvest information. Date of harvest is one of many variables in the table....
3
by: Robert | last post by:
I need to set up a query that will pick out records for the current winter season. I.e., each season runs from October 1 until March 31. The catch is, the year can't be hard coded. So, if the...
8
by: luke64 | last post by:
Apolgies if this has already been answered... Right, I have a season table where I specify each season (Winter, Summer, Spring etc.) with a 'date from' and 'date to' field which is formatted as...
6
Atli
by: Atli | last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users. Anyone should be able to get...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.