- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Ha! Obviously he means that it's not feasible without programming knowledge, something absent from his miniscule head!
Admin
lol
Admin
C'mon... they don't matter... give the guy a break. I mean, it's not like there's a really easy way to do things or anything.
Admin
Hang on, that last query would work, wouldn't it?
Admin
<font>DECLARE </font><font>@TodayIsMarchFirstAndYesterdayWasFebruaryTwentyEighth</font>
<font>
SELECT
</font><font> @TodayIsMarchFirstAndYesterdayWasFebruaryTwentyEighth =
CASE
WHEN
DatePart(month, getdate()) = 3 AND
DatePart(day, getdate()) = 1 AND
DatePart(day, getdate() - 1) = 28
THEN 1
ELSE 0
END
</font><font>
IF @TodayIsMarchFirstAndYesterdayWasFebruaryTwentyEighth
BEGIN
</font>
SELECT CustomerId, EmailAddress
FROM Customers
WHERE
(BirthMonth = 3 AND BirthDay = 1) OR
(BirthMonth = 2 AND BirthDay = 29)
END
ELSE
BEGIN
<font>SELECT</font> CustomerId, EmailAddress
<font>FROM</font> Customers
<font>WHERE
BirthMonth</font> = <font>DATEPART</font>(month, getdate()) <font>AND
BirthDay = DATEPART(day, getdate())</font>
END
Admin
Oops forgot the bit stuff
<font>DECLARE </font><font>@TodayIsMarchFirstAndYesterdayWasFebruaryTwentyEighth</font> AS BIT
...
IF <font>@TodayIsMarchFirstAndYesterdayWasFebruaryTwentyEighth = 1</font>
<font>
</font>
Admin
As the article says, it will miss anyone born on February 29 (you'd want to give them the coupon on either the 28th or March 1st).
Other than that, yes, it would work.
Admin
doesn't quite work... but he's right this is a big pain in the butt. you can't just do
... OR ( sysdate = feb 28 and birthday = feb 29)
since in a leap year a feb 29 person would get TWO emails... one on the 28 and one on the 29 (their actual birthday). That means you need to add logic to know if its an actual leap year.
this is starting to look pretty hard to do
Admin
Or, you could do what I do, and just treat them like lepers with no social standing whatsoever.
Admin
I thought that people who are born on Feb 29th, usually officially declare their birthday as either February 28th or March 1st, so it still shouldn't be an issue.
Technically though,if they put in their birthdate as 2/29, then their birthday only comes every four years(excluding the century exclusions of course), so the query is correct.
Admin
I don't believe this for a minute! Do you think I was born yesterday?
Admin
Mostly, yes. The problem is that if it isn't a leap year then February 29th will never happen and the people born on February 29th would not get the birthday messages for that year. What is funny is that it would be relatively trivial to check for February 28th and return records for both people born on the 28th and the 29th.
Admin
<FONT face=Georgia>I love the fact that somebody had to point that out to him... Hey, at least he's thinking about the customers of the future!</FONT>
Admin
wow, i actually laughed at this WTF, not cause of the actual wtf but cause of what this dude said :>
Admin
As some other people have pointed out while I posted, it is not that trivial from within the query itself. It would however be trivial in the logic surrounding the code that calls this query to check the date and whether or not it is a leap year and call one of several different queries depending on the results, one for 28th non-leap year, one for 28th in a leap year, and one for 29th in a leap year.
Admin
Easy in Postgres
SELECT customerid, emailaddress
FROM customers
WHERE extract(years from age(birthdate))
!=
extract(years from age(birthdate + '1 day'::interval))
Admin
Admin
Shouldn't this work?:
WHERE DATEPART (day, Birthday-1) =DA<font>TEPART</font>(day, Today() ) AND DATEPART (month, Birthday-1) =DA<font>TEPART</font>(month, Today() ) AND WHERE DATEPART (day, Birthday) =DA<font>TEPART</font>(day, Today()+1 ) AND DATEPART (month, Birthday) =DA<font>TEPART</font>(month, Today()+1 )
Admin
Ah, now I understand!
The article says "the query only ignores those born on the 29th in a non-leap year" and I thought to myself "nobody is born on the 29th in a non-leap year".
I now realise the article should have said "the query, when run in a non-leap year, ignores those born on the 29th"
(I once read that the septics use less commas than the brits do in their version of english, so I guess communication failures across the pond are inevitable)
Anyway, now that I understand the problem, it does seem less-than-trivial to me...
Admin
Just take the Alice in Wonderland approach: choose a random date for each customer to wish them a Happy Unbirthday. You would only have to look at the day number of birthdate to ensure correct unbirthday greetings.
Admin
SELECT CustomerId, EmailAddress
FROM Customers
WHERE
DATEPART(dy, DATEADD(d, -DATEPART(dy, GetDate())+1, DATEADD(year, DATEDIFF(year, @Birthdate, GetDate()), @BirthDate)))-1 = 0
Works for leap years, February 29's, everything. Pulled it right out of my big box of random ingenious code snippets (no, I did not write it, but I also don't know who did). Translate into your DB of choice.
Extra points if you can work out why it works. [;)]
Admin
Jeesh, haven't you been paying attention?
Postgres isn't "Enterprise Class". Stop getting hung up on the fact that you can get it to do exactly what you want it to do.
Admin
"Unfortunately, he's not very strong at estimating the technical challenges of the request or determining who on the team has the time to implement the requirements."
That's nothing.
I had a marketing guy slip up on me.
He told the customer he could have two X Window SERVERS running on an embedded system target platform.
He should have said, Two X Window SCREENS. (Or alternately, one dual head X Window Server)
two screens: dual head, one mouse, one keyboard.
two servers: two separate single-head X servers, each with their own mouse and keyboard an everything.
One word. He screwed up one word.
It took a YEAR of development to fix his mistake.
GAAAAAAAAAAAH!
Admin
http://r937.com/birthdays.html
Go, go, google. [H]
Admin
I did it a little differently... slightly shorter and doesn't need DATEPART
... WHERE
DATEADD(day, -1, DATEADD(year, DATEDIFF(year, @BirthDate, getdate()), @BirthDate)) = GETDATE()
Admin
The first SQL statement is obviously wrong. It should read:
Admin
For those born on the 29th of Feb, I'd only give them coupons if this year is a leap year, and it is the 29th of Feb. For fairness, I'd give them four coupons. Well, not exactly four. Since 2400 isn't a leap year, but 2000 wasn't, they're entitled to an extra 0.99%. So, they'd get 4.0396 coupons.
The car companies are currently giving out employee discounts to everyone. What? You didn't know that you work for Ford, GM and DCX?
Admin
Agreed. I registered just to say this is better than the WTF and one of the best comments posted. I must incoporate this philosophy in my daily job.
Admin
I am really new to the whole database thing and without knowing how they have their schema set. I will take a wild stab in the dark at this one. I am being overly verbose here - in production it would be squished down to a manageable query.
declare @birthday datetime
SELECT @birthday = birthday FROM Users WHERE [id] = xx
declare @year int
SET @year = DATEDIFF(year, @birthday, GETDATE())
declare @couponDay datetime
SET @couponDay = DATEADD(year, @year, @birthday)
SET @couponDay = DATEADD(day, -1, @couponDay)
Should this not get you a coupon day as the day before their birthday? This should probably compress down to just a pair of selects. All we really are is uping the year component to the current year and then subtracting a day to get the day before their birthday.
The interesting part comes if you have a date that does not exist in the current year (say Feb. 29th) what happens when you add a year? With MS SQL (the only one I have to test against) it will select February 28th - thus the above will treat your birthday as Feb 28th when the 29th does not exist.
Admin
For mysql:
...where date_format(curdate(), '%m %e')=date_format(BirthDay, '%m %e') or date_format(date_add(BirthDay, interval 1 day), '%m %e')=date_format(date_add(curdate(), interval 1 day), '%m %e');
first clause matches the current day and the second clause...
Admin
...and doesn't seem to work for Feb 29th.
Admin
<font size="2">The real WTF is that people still use coupons.
</font>
Admin
What I really want to know is, what kind of customer is going to believe a developer that tells them it is "not feasible" to determine if it is the day before someones birthday!
Admin
<sarcasmn>See, now all this date nonsense could be COMPLETELY avoided if we were to use 16 months in a year, 16 days in a month, and 16 hours in a day. I mean seriously people, we are using ANCIENT date technology. Of course, with 16 days in a month, a week would be 4 days long, and the weekend would be 1 day... but it all works out ;-) </sarcasmn>
Admin
All together now... "But you treat everybody like lepers with no social standing whatsoever."
Admin
2000 was a leap year. 2400 will be a leap year. It is 2100, 2200, 2300, and such that we have to worry about.
Can I put that in my resume? <EG> I got an employee discount from one company that I had not worked for for about two years. The boss gave it to me.
Sincerely,
Gene Wirchenko
Admin
Actually, it should have said "the query, when run in a non-leap year, ignores those born on the 29th of Feb.during a leap year." There are 11 other 29ths of the year that are not ignored.
A WTF in the WTF?
Admin
Not the sharpest knife in the drawer.
What would be funny would be such a line being delivered to someone who does know. Likely response: "Are you incompetent?"
Sincerely,
Gene Wirchenko
Admin
I, as an American, who, incedentally, is not familiar with the term "septic," except as relating to a tank full of shit, would like to state, for the record, that I proudly, and frequently, use commas, even though I reside, as you may have guessed, on the \X/estSide of the Atlantic Ocean, or, as you insist on referring to it, the "pond."
Admin
I got a $300 television from Best Buy for $5, out of the store - no rebates, only coupons.
Admin
2000 is already gone, 2100 is unreachable. 2038 is the end.
</eg>
Admin
>>>
I, as an American, who, incedentally, is not familiar with the term "septic," except as relating to a tank full of shit, would like to state, for the record, that I proudly, and frequently, use commas, even though I reside, as you may have guessed, on the \X/estSide of the Atlantic Ocean, or, as you insist on referring to it, the "pond."
<<<
Glad to hear it! :-)
PS: The term "septic" is from Cockney-rhyming-slang. (http://www.cockney.co.uk/) You'll find a translation of it here http://www.cockneyrhymingslang.co.uk/cockney/letter/S.aspx
PPS: Believe it or not, it's not actually intended to be offensive.
Admin
I don't know - doesn't look like much of a WTF to me... if the first query (the one that only selected people born tomorrow) went into production, that would be one thing, but what I see here is a feature that could have been a pain in the ass to implement, and was dropped. As many of you have mentioned, this is tougher to do than it seems.
--Daniel T
p.s. I could even see myself thinking in terms of the first query: "if birthday == today..."
Admin
Actually, you only need one extra query with this approach - one run on the 27th of Feb in non-leap years that returns customers born on the 28th or 29th of Feb. Writing this is left as an exercise...
Admin
I once read that the brits need correcting from the STs on the usage of "less" versus "fewer".
Admin
<WARNING content-status="off-topic">
<warning content-status="off-topic">
I thought surely the english spoken in england is correct by definition,
but maybe less americans make less mistakes and cause fewer confusion because what is said is fewer incorrect.
</warning></WARNING>
Admin
Actually, it should have said "the query, when run in a non-leap year, ignores those born on the 29th of Feb."
Let us, (meaning all of us (who are reading this (on TDWTF (using a browser (or RSS or Email))))) not be redundant.
Admin
Nobody thought of that ? :
DECLARE @vTomorrow as datetime
, @vIsYourBirthDay as tinyint
SELECT @vTomorrow = DATEADD(d, +1, GetDate())
SELECT @vIsYourBirthDay = CASE WHEN Day(BirthDate) = Day(@vTomorrow) and Month(BirthDate) = Month(@vTomorrow)
THEN 1
ELSE 0
END
FROM tblTableWhereYourBirthDateIS
I wrote it very quickly but it seems to me it would work, wouldn't it?
Admin
and a solar year would be approx 2.138671875 of your NEW AND IMPROVED years long. No thanks, I'm getting too old too quickly already!
Admin
Why not simply say that if your birthday is after the 28th, then it sends you a coupon on the 28th?