473,770 Members | 6,506 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

mysql date within season

3 New Member
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 3659
amitpatel66
2,367 Recognized Expert Top Contributor
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
dennisfreud
3 New Member
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 Recognized Expert Specialist
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
dennisfreud
3 New Member
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 Recognized Expert Specialist
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
1336
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 anyone know of a free host that provides MySQL? Or even better, does anyone have experience of this? I've created an ASP web interface to an Access database and read/written to it like that in the past so I assume it's the same for MySQL.
1
1899
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 order the results alphabetically but wondered whether you can define the order in the query. Any help would be appreciated,
3
1262
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 try to build the date from the components (i.e d.getMonth() etc...) the result is an incorrect date. How can the date be both correct and incorrect at the same time? The intial alert(d); displays correctly, but the alert(t + "/" + m + "/" + y);...
8
7000
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 be done by a function generate_ssid() and works fine. next step is to register the ssid in the table session this will be done by the following code: ************************************************************************* function...
3
1943
by: Lloyd Stevens | last post by:
TABLES CustomerTable CustomerTarrifTable TarrifTable WarrantTable CustomerID(P) CustomerTarrifID(P) TarrifNo(P) WarrantID(P) BoatType QuantityPurchased ProductName WarrantDate CustomerName Cost QuantitySold Season Cost TarrifNo Season CustomerID TarrifNo
0
1424
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. Since our season runs from the first SAT in October to 31 January, valid harvest dates for 2005-06 were 4 Oct 2005 to 31 Jan 2006. Many records will have missing or dates outside of this range. Date is needed to assign each dead deer to a...
3
1734
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 query is run on September 30 of this year (2006) it should show all records with a date between October 1, 2005 and March 31, 2006. If that same query is run on October 1, 2006 it should show all records with a date from October 1, 2006 through...
8
2365
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 dd/mm (no year). I also have a property table that defines a properties grade, I also have a table used to define each grade ('Grade', 'Description') Then finally I have a relationship table which covers 'Grade', 'Season', and 'Price'. I need...
6
38519
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 through this without much trouble. Programming knowledge is not required. Index What is SQL? Why MySQL? Installing MySQL. Using the MySQL command line interface
0
9591
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9425
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10057
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10002
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9869
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6676
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5312
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5449
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3970
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.