Jump to content

Recommended Posts

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

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.