Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calculate Birthday
Message
From
21/02/2001 17:00:52
Bob Lucas
The WordWare Agency
Alberta, Canada
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Calculate Birthday
Miscellaneous
Thread ID:
00478188
Message ID:
00478188
Views:
58
I have a little asp code that scrolls a marquee on a web page listing the names of people (office staff) whose birthday occurs within the next 7 days. The routine worked fine for at least the last 9 months or so until this morning. I got a call from the user because the page was 'broken'.

Turns out it was datetime error. What I was doing is taking the day and month of the person's birthdate, adding the year (all as a string) and converting to a date. This date I then compared to Getdate() and Getdate + 7.

The problem was, somebody has a birthday that fell on Feb 29th of some previous year. When I tried to create a compare date of Feb 29 2001, of course I got a date error!

I know I can fix this code, making it a little more complicated, maybe changing a select statement to a stored proc, but it got me wondering if someone has an elegant piece of T-SQL that already does this!

Otherwise, what may be simplest, is to pick a year where Feb 29 was okay, then parse out the day and month of today, make a new date using the okayyear for both sides of the comparison. Not so elegant but the year doesn't matter!
Next
Reply
Map
View

Click here to load this message in the networking platform