Information générale
Forum:
Microsoft SQL Server
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!
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement