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. Quote 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`)) Quote Link to comment https://forums.phpfreaks.com/topic/199545-combining-day-and-month/#findComment-1047464 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.