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
https://forums.phpfreaks.com/topic/28627-slightly-more-advanced-date-calculations/
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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.