.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> Sql Server >> Post New QuestionBookmark and Share Subscribe to Forum

How to find next upcoming birthdays after 15 days using sqlserver?

Posted By: Syed Shakeer Hussain     Posted Date: August 23, 2009    Points:2   Category :Sql Server
Suppose in table a have a column birthdate values as:
2-09-2009
4-09-2009
12-08-2009
25-09-2009

i want output only below records(coming in next 15 days Birthday records)

2-09-2009
4-09-2009


Responses
Author: Amit Mehra             
Posted Date: August 23, 2009     Points: 5   

Hi Syed,
you can use GetDate() and dateadd() function of sql server to get the reminder date for the next 15 days

for eg

select * from [TableName] where DateColumn between getdate() and dateadd(day,15,getdate())


Hope i understood your question

Thanks,
Amit
Please "Mark As Answer " if this post help you.
Author: Syed Shakeer Hussain             
Posted Date: August 23, 2009     Points: 5   

Hi Amith,
Again Nice query.
I wrote query in another way.

SELECT * FROM EMPLOYEES WHERE day(birthdate) =day((GETDATE()+15)) AND month(birthdate)=month(getdate())

My query is little bit hard.your query is in simple way........

Author: Amit Mehra             
Posted Date: August 23, 2009     Points: 5   

My Pleasure Syed...well even i learn a different way to get result. Thanks for sharing your query..

Thanks,
Amit
Please "Mark As Answer " if this post help you.
Author: Syed Shakeer Hussain             
Posted Date: August 24, 2009     Points: 5   

Hi Amith,
Above our both queris are not working.
it is ckeching year also
Quesry has to check omitting year

Author: Amit Mehra             
Posted Date: August 24, 2009     Points: 5   

I am sorry Syed..here is your query you can use datepart() function to avoid year and get the birthday reminder sql query


select * from <Table_name> where datepart(dayofyear, <Birthday_Column_Name>) between datepart(dayofyear,getdate()) and datepart(dayofyear, dateadd(day,15,getdate()))


Thanks,
Amit
Please "Mark As Answer " if this post help you.
Author: Syed Shakeer Hussain             
Posted Date: August 24, 2009     Points: 5   

Very very very Good ansewer Amith..

Author: aspnet             
Posted Date: February 03, 2011     Points: 5   

Thanks Amit. Your script really helpful, especially the eliminating of year part.

I modified your script a little to suite my need:

select * from <Table_name> where datepart(dayofyear, <Birthday_Column_Name>) between datepart(dayofyear,dateadd(day,7 ,getdate())) and datepart(dayofyear, dateadd(day,2,getdate()))


My project asks that I have to display birthdays 7 days in advance, and a birthday display lasts 2 days after that. It works like charm. I post it up here in case someone may find useful.

Thanks again.

Author: Syed Shakeer Hussain             
Posted Date: February 03, 2011     Points: 5   

Hi aspnet,
Thanks for sharing your query



Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend