bastienvans Posted April 23, 2010 Share Posted April 23, 2010 Hey everyone, I am trying to select dates in between 2 columns, "starting" and "ending". I do not want to include the year, so I use the DAY() and MONTH() functions. This is part of my sql: SELECT * FROM rates WHERE DAY('2010-02-05') BETWEEN DAY(`starting`) AND DAY(`ending`) and SELECT * FROM rates WHERE MONTH('2010-02-05') BETWEEN MONTH(`starting`) AND MONTH(`ending`) Both works, but when I try to combine them, it returns every rows in my table, regardless of input date. SELECT * FROM rates WHERE (DAY('2010-02-05') AND MONTH('2010-02-05')) BETWEEN (DAY(`starting`) AND MONTH(`starting`)) AND (DAY(`ending`) AND MONTH(`ending`)) For instance, if the input date is "2010-05-07", I want "05-07" to be selected through my table, not "05" OR "07". I am having a hard time explaining what I am trying to accomplish, but hopefully my description is accurate enough. Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/199545-combining-day-and-month/ Share on other sites More sharing options...
andrewgauger Posted April 24, 2010 Share Posted April 24, 2010 Try: SELECT * FROM rates WHERE (DAY('2010-02-05') BETWEEN (DAY(`starting`) AND (DAY(`ending`)) AND (MONTH('2010-02-05') BETWEEN MONTH(`starting`) AND MONTH(`ending`)) Link to comment https://forums.phpfreaks.com/topic/199545-combining-day-and-month/#findComment-1047464 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.