Hello Everyone.
i have query for upcoming birthday,
i want when user log in then on welcome page user can see upcoming birthday of next 10 days from the current date of their contact. i wrote this
select FirstName,DOB from PersonalAddBook where month(DOB)=month(getdate())
AND day(DOB)>=day(getdate()) order by DOB asc;
but the problem is this its only return same month's birthday result. like today is 27th April. and if my frnd's b'day is on 1st May then its not showing, i want,. query which always count 10 days from the current date and show. if any b'day is coming in tht 10 days period.
please update my query nd tell me how can i get the desired result.
Thanks
Loading
Rashid KhanPosted Apr 29, 2010, 6:30 AM
i also made this mistake. we cannot check year.
i just want, tht query which can filter tht DOB from database and check tht it'll come in next 10 days of the current day, if yes then return name nd DOB frm DB
i think i have to use CAST something like this.
select FirstName,DOB from PersonalAddBook where CAST(CAST(MONTH(DOB) AS VARCHAR(2)) + '/' +
CAST(DAY(DOB) AS VARCHAR(2)) + '/' +
CAST(YEAR(DOB) AS VARCHAR(4))AS DATETIME)between getdate() and getdate()+10
but it returns nothing, but i think it can be solved by this way,
so can anyone please help me so tht i come out from this issue.
Thanks.
Hirendra SisodiyaPosted Apr 27, 2010, 4:16 AM
try this code
DateTime StartDate = DateTime.Now;
DateTime enddate = StartDate.AddDays(10);
string str = "select FirstName,DOB from PersonalAddBook where DOB >=" + StartDate + " and DOB <= " + enddate + " order by DOB asc";
thanks
please mark as answere if it helps