find birthday |
[eluser]Bigil Michael[/eluser]
i want to find birthdays between two dates my table structure is Code: id dateofbirth birthday birthmonth email i want to find out birthdays between 2 dates? if 2 days are like this 2011-02-01 and 2011-02-28 it will show correct result if i change the month 2011-02-01 and 2011-03-01 it doesnot give correct result????? query used is Code: function list_date_email($d1,$m1,$d2,$m2,$limit,$pgoffset) i want to know what is the change required in the query to calculate birthdays between any two dates??? or any other method to find the birthday between two dates???? thanks in advance.....
[eluser]RobertB.[/eluser]
Maybe this help, I don't know why you are making extra columns for dates and months but I don't think that you need them. This will return the 3 dates Code: WHERE dateofbirth >= '2010-08-02' AND dateofbirth <= '2010-08-03' Code: $this->db->where('dateofbirth >=', '2010-08-02'); This will return the 1 date Code: WHERE dateofbirth > '2010-08-02' AND dateofbirth < '2010-08-03' Code: $this->db->where('dateofbirth >', '2010-08-02'); hope this is what you're looking for.
[eluser]Bigil Michael[/eluser]
thanks for your reply but this is not the required result i want to find out the birthdays eg: find the persons with birthdays within 2011-02-01 and 2011-02-03 then the result must be like this Code: persons with birthdays within i think now u got the idea here year is not important only day and month are important so i generated birthday and birth month.... if possible please help?? urgent any other method to calculate the result is also accepted...
[eluser]tomcode[/eluser]
What's about : Code: function list_date_email($d1,$m1,$d2,$m2,$limit,$pgoffset)
[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 |
Welcome Guest, Not a member yet? Register Sign In |