Welcome Guest, Not a member yet? Register   Sign In
find birthday
#6

[eluser]mcrumley[/eluser]
You can't compare the month and day separately. Consider the following date range: 2011-01-01 to 2011-03-01. The day part is always 1, so any date that is not the first day of the month will not match.

You need to compare both month and day together. You could do a string comparison using only the month and day.

Code:
DATE_FORMAT(dateofbirth, "%m-%d") BETWEEN "01-01" AND "03-01".

Another way is to multiply the month by 31 and add the day. That will calculate a unique ordered number for each day of the year, avoiding issues with leap years that come up using day-of-year calculations.

Code:
MONTH(dateofbirth)*31 + DAY(dateofbirth) BETWEEN 1*31+1 AND 3*31+1


Messages In This Thread
find birthday - by El Forum - 02-07-2011, 10:45 PM
find birthday - by El Forum - 02-07-2011, 11:25 PM
find birthday - by El Forum - 02-07-2011, 11:54 PM
find birthday - by El Forum - 02-08-2011, 03:18 AM
find birthday - by El Forum - 02-08-2011, 04:14 AM
find birthday - by El Forum - 02-08-2011, 09:57 AM



Theme © iAndrew 2016 - Forum software by © MyBB