Get ready for BLACK FRIDAY shopping starting in

Forums

ASP

This topic is locked

Advanced Date Search

Posted 03 Sep 2004 20:46:51
1
has voted
03 Sep 2004 20:46:51 colin hart posted:
I have a database field that is for Birthdays and records the data like this 01/01/1970. I want to do a report that will show all birthdays say for the next 30 days. I can't just do a normal Getdate+30 because of the year. Any suggestions.

Almost forgot.
sql2000, ASP, VB, using Dreamweaver MX

Replies

Replied 05 Sep 2004 18:15:22
05 Sep 2004 18:15:22 Andrew Watson replied:
Many ways..

but heres a sql statment for an access db that will return all birthdays in the next 30 days...
sql can vary slightly across db platforms..

It calculates the years since their birthday..
then works out their birthday this year...
then just filters this value out for greater that or equal to today AND less than or equal to the date in 30 days time.

or you could do it in your while loop
or.. or... or.. or...
this method is probably the fastest and easiest to modify (just change the 30 to whatever to change range)

<pre id=code><font face=courier size=2 id=code>"SELECT tbl_birthdays.str_name, tbl_birthdays.dat_birthday, DateAdd(""yyyy"",DateDiff(""yyyy"",[dat_birthday],Date()),[dat_birthday]) AS this_year " &_
"FROM tbl_birthdays " &_
"WHERE (DateAdd(""yyyy"",DateDiff(""yyyy"",[dat_birthday],Date()),[dat_birthday]) &gt;= Date() AND DateAdd(""yyyy"",DateDiff(""yyyy"",[dat_birthday],Date()),[dat_birthday]) &lt;= Date()+30);" </font id=code></pre id=code>

SQLServer2000 Supports Date/Time functions


:: Son, im Thirty.... ::

Edited by - leed on 05 Sep 2004 18:19:30

Reply to this topic