Querying dates

Hello,
I want to create a program to remind people of their birthdays 5 days before their birthday..everyday till their birthday pasees by.
I have a list of records with peoples birthdays on sqlserver database.I want to set a reminder of peoples birthdays 5 days before their birthday.I want to be reminded on every one of those 5 days till their birthdays ends.How should the query be? Please help,
Thanks.
godwindotnetAsked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
>On every one of those 5 days,i want to be reminded till.... their birthday is over.


select * from yourtable
where convert(varchar(5), birthdate , 101) = convert(varchar(5), dateadd(day, 5, getdate()), 101)
or convert(varchar(5), birthdate , 101) = convert(varchar(5), dateadd(day, 4, getdate()), 101)
or convert(varchar(5), birthdate , 101) = convert(varchar(5), dateadd(day, 3, getdate()), 101)
or convert(varchar(5), birthdate , 101) = convert(varchar(5), dateadd(day, 2, getdate()), 101)
or convert(varchar(5), birthdate , 101) = convert(varchar(5), dateadd(day, 1, getdate()), 101)
or convert(varchar(5), birthdate , 101) = convert(varchar(5), dateadd(day, 0, getdate()), 101)
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
what database?
table structure?
0
 
godwindotnetAuthor Commented:
Just imagine there are 5 columns in a database and one column is the birthday column where the persons birth date is stored.
Now,there are probably 1000s of records in the database.(Just keep the birthday column in mind,forget what other columns are...im just saying this as an example for what i want to implement in my project.)
I want to send queries everyday and i want to send reminders(imagine im sending reminder emails to myself) 5 days before anyones birthday approaches.
On every one of those 5 days,i want to be reminded till.... their birthday is over.

Im using sqlserver 2005 express as database.Vb.net as front end.
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
godwindotnetAuthor Commented:
And Thanks for the quick response Angel...it was just 2 minutes after i posted...:-)
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:


select * from yourtable
where convert(varchar(5), birthdate , 101) = convert(varchar(5), dateadd(day, 5, getdate()), 101)
0
 
godwindotnetAuthor Commented:
Give me few minutes angel..Ill try this what youve given with my program and getback
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
to make the above performant, you should make a computed field on your table containing the value of
convert(varchar(5), birthdate , 101)
+put an index on that field
+use that field instead of the convert()... in the query
0
 
godwindotnetAuthor Commented:
You deserve 2000 pointrs,but EE lets me give only 500 :-(
Thanks a tonne for that answer and for the time you took for me :-)
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
actually, with the grade A, I got 2000 points (500x4)
Glad I could help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.