Jump to content

Combining DAY and MONTH


bastienvans

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

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.