Jump to content

Slightly more advanced date calculations


zq29

Recommended Posts

I have a books table that holds information about hotel bookings, I am trying to pull out all records where the client is due to leave their hotel room within 5 days. I'm string the start day, month and year in separate fields and the duration in a field. Here's what I have so far, although it doesn't appear to be pulling the correct rows - It is returning data, but I can't figure out why it's returning what it is. I assume I'm doing this wrong, so any chance someone could take a look at my query?

[code]SELECT * FROM `booking` WHERE DATE_ADD(CURDATE(),INTERVAL 5 DAY) <= DATE_ADD(CONCAT(`start_date_y`,'-',`start_date_m`,'-',`start_date_d`),INTERVAL `nights` DAY)[/code]
Link to comment
Share on other sites

I've got DATE_ADD on both sides as I want to compare 5 days from the current date, to a start date plus a duration (to form the end date).

I'm not as knowledgeable in MySQL, so I just tried adding in a column as an interval value, and it didn't spit out any error messages so I guess it's valid... Although there is an error somewhere as it's not returning the expected results - Maybe it [b]is[/b] invalid to use a column as an interval and thats why my results are unexpected?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.