- 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
Ewww ... he hangs around with MySQL!
Admin
Why bother doing date parsing in SQL anyway? Just get all unique customer ID and email
and shove it into something like PHP/C/[insert favourite langauge] and parse
date from there.
If you were really picky about performance loss due to pulling out ALL the entries,
just SELECT entries by today's month only and pass that to your script.
You have to pass the data to your script/program anyway, to be able to send email.
Admin
Everybody is focusing on leapyears, but really isn't the WTF that the coupon email is being sent on a specific day? I mean, do you want to go poking around in there if the code doesn't run for some reason for a day or two and you have to back up time in order to send out belated birthday coupons?
"No Problem, just roll back the system date and re-run it!!"
And there's no check field to store if coupon has already been sent. At least none that we can see.
Birth days are always a bitch, better to use birth week.
Admin
A lazy programmer .. one of the great virtues.
Admin
reminds me of the simpler calendar
--
rien
Admin
i meant simpler calendar
-- rien
ps: that's true, this forum software s****...
Admin
Actually, I'd have recommended the same thing.
A) Last minute fix
B) The importance of receiving it one day before your birthday to someone born on the 29th is probably not that high and that, statistically, there aren't very many people whom might be affected by this triviality.
C) How are you going to guarantee the coupon shows up in the mail on someone's birthday anyway? If their birthday is on Sunday they're SOL. If their birthday is December 25th (or any other federal holiday that the post office gets off) they're not getting the coupon on time either. At what point do you just accept that with the calendar some things are simply "close enough" and not paint yourself into a corner of doing really complicated date/time logic when it only solves a problem with one statistical outlier and does nothing at all to fix a much larger body of statistical anomalies?
Admin
Strangely, my post didn't quote Djinn whom said:
>A lazy programmer .. one of the great virtues.
Whom was replying to: "Why not simply say that if your birthday is after the 28th, then it sends you a coupon on the 28th?"
Admin
Steve shoulda out-sourced the project after the second episode.
Admin
I guess that, to me, the real WTF is that Steve let the programmer say such a thing to a client.
Admin
Absolutely bang on target. The real WTF is the short-sighted client. Most marketing efforts are sent out well in advance of a target date - to ensure plently of time for unforseen delivery issues. The time-frame is *way* to compressed. The client is the real knuckle-head. - Probably reacting to a qualified suggestion from the sales department.
This supports what I've been saying for years... "We gotta find a way to do business without clients."
Admin
I was presenting one of my programs one day to a group of managers prior to it release into production. The code was written in less then 1 hour but would have saved some administrators including my self around 2 hours a day. It connected to AD and our DB and provided a basic report.
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>
Managers who knew the process were impressed. At the end of the meeting I was told by one of the managers that it took more then 2 hour for 8 people (7 managers +1 consultant from unnamed vendor) to determine that what I just did was impossible within time and budget constrains of one month and a lot of $.
<o:p> </o:p>
I have spent another 4 hours documenting the code and sent it to our testing team. A week later I asked if the software has been approved. It turns out that some managers took my cations as criticism of their management and decision making abilities and blocked the release. The reason was simple – They “did not what the code did.”
[*-)]
Admin
Sorry for the spelling mistakes. I am on 4 hours of sleep. <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
"managers took my actions" and They “did not know what the code did.” I am sure there are more. <o:p></o:p>
LOL, English is my third language. <o:p></o:p>
Admin
The word 'seppo' itself is not Cockney in origin as far as I am aware (although the rythming slang pattern is). I always thought it was Australian and I think it had it's origins in WWII.
http://english2american.com/dictionary/cat_people.html
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.
Yeah, this is the correct behaviour in my opinion. My grandfather was born Feb 29 1888. We celebrated his 21st "birthday" when I was a kid and he was 88 in elapsed years.
We even got a picture in the paper of him surrounded by all his grandkids celebrating his '21st' birthday. As far as he (and my great grandparents) were concerned he just lucked out on the birthday stakes and so he only got a birthday every four years but apparently he got lots more attention whenever that did happen. Worst luck was being born just before the century so he didn't even get a 12th birthday. On the other hand, being born in Glasgow, Scotland, just before the turn of the century, I imagine presents might have consisted of a pat on the back and maybe an orange if you were lucky but probably not. (cf Monty Python Four Yorkshiremen Sketch - I don't want to dishonour Mac's name by making the joke myself but you can imagine it).
So yeah. If you happen to be 'lucky' enough to have a birthday on the leap day, then I imagine not getting promtional birthday cards from some sorry arse marketing firm that you don't care about anyway is not top on your priority list.
Admin
www.newsaves.com
Admin
You mean your e-mail doesn't get delivered on Sunday or holidays? It's talking about coupons being sent to e-mail addresses....the first SQL statement contains the clue.
Admin
<FONT size=2>I think the query just needs an OR.</FONT>
<FONT face="Courier New" size=2>-------------------------
SELECT
CustomerId,
EmailAddress
FROM
Customers
WHERE // TOMORROW IS THE BIRTHDAY
(
DATEPART(day, Birthdate) = DATEPART(day, Today() + 1)
AND DATEPART(month, Birthdate) = DATEPART(month, Today() + 1)
)
------------------------------</FONT>
<FONT size=2>so assuming that today() returns a date, and today()+1 returns tomorrow, the real test is for tomorrow.</FONT>
<FONT face="Courier New" size=2><FONT face=Tahoma>there is only one possible exception... that being FEB 29.
lets add.... </FONT></FONT>
<FONT face="Courier New" size=2><FONT face=Tahoma>
</FONT>-------------------------
OR (
( DATEPART(day, Today() + 1 ) = 1 ) // TOMORROW IS THE FIRST OF THE MONTH
AND ( DATEPART(day, Birthdate) > DATEPART(day, Today()) ) // AN OVER-RUN</FONT>
<FONT face="Courier New" size=2> ) //....then it must be a leap year baby and it must be FEB.</FONT>
Admin
I prefer the one with 13 months all with 28 days, you always know what day of the week any day of the month is (e.g. 1st, 8th, 15th, 22nd are always Sunday, etc.) and there are only two special days, New Years Day and Leap Day.
Admin
ahhh!!!! it looks way too much like lisp...
Admin
Can anyone here spell 'loosely coupled'? (In the app. login indeed ....) :|
Admin
OMG, I just fell right off my chair.......... You go girl!!!!
Admin
I know one person born on Feb 29, and he adamantly states his age according to the number of "real birthdays" he has had, approximately his real age divided by four.
You can not begin to understand how many wrenches this throws into the machinery of various systems.
He actually tried to use this to get out of military service, and I've seen hem spend 20 minutes argueing that he should only pay for a child ticket for the train (and eventually succeeded, mostly because the queue behind him were beginning to look like a mob).
In other words, the code may not be that much wrong...
Admin
Gilbert and Sullivan used leap years as a crucial point in their Pirates of Penzance musical.
Pirate King: You were apprenticed to us!
Frederick: Until my twenty-first year.
Pirate King: No... until your twenty-first birthday - and going by birthdays you are, as yet, only five... and a quarter.
...
Frederick: I've bound myself to serve the pirate captain... until I reach my one-and-twentieth birthday!
Mabel: But you are twenty-one!
Frederick: I've just discovered that I was born in leap year... and that birthday will not be reached by me till 1940.
Given that the play begins when Frederick is twenty-one years old... what year is it?
Admin
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".
Apart from the point, already made, that there are plenty of "29th's" in every year, including non-leap years, we've got a programmer who couldn't quite figure out how to overcome the error pointed out to him ... about the roughly 0.06% of people who might not get a coupon in the suggested code. That is, less than one birthday out of 1460 might not result in a celebrant being given his or her due.
So the manager claimed it was infeasible, rather than merely delivering 99.9993% of the coupons management wanted to deliver.
Yeah, that's an error I'd cancel whole projects about.
Admin
Well, my money's on the early hours of this morning
Admin
SELECT CustomerId, EmailAddress
<FONT size=+0>FROM</FONT> Customers
<FONT size=+0>WHERE</FONT> dbo.anniversary(Birthdate) = 'Y'
Simple really.
Admin
I would argue that the second query is absolutely correct. I don't really see the WTF here. By convention, the leap year lepers only have a birthday every fourth year.
Pirates of frigging Penzance, anyone?
Admin
Oh curses. I should have read the second page. Some scurvy dog has already pointed out the Pirates of Penzance.
Admin
For marketeers they're great. Print a million coupons worth $5 each, claim you're giving away $5 million.
In reality only a few thousand get turned in, actual cost maybe $15000 plus the cost of printing and distributing the darn things (which is even less, and zero if you make them "downloadable" which is the current trend).
The suckers are the customers who prefer coupons over real discounts :)
Admin
No, they just need reminding that not everyone knows their language well enough to know the difference.
Admin
Spelt "minuscule"...
Admin
That is a WTF. And... if you only pull out entries for current month, then you totally ignore everyone both on the 1st of the month.
Admin
Now, why don't we start looking at the code behind this forum for some serious jaw-dropping WTF?!
Admin
Just another solution: build a time-machine
Admin
Can't help it. I've worked for the Department of Redundancy Department far too long.
Admin
"(cf Monty Python Four Yorkshiremen Sketch - I don't want to dishonour Mac's name by making the joke myself but you can imagine it)."
Just to clarify: that sketch actually predates Monty Python - it was originally in "At Last The 1948 Show" (see http://en.wikipedia.org/wiki/At_Last_the_1948_Show), but it was MP who made it famous.
Admin
Actually, Atomic, I think Djinn was agreeing with me as well.
A lazy programmer can be a good or bad thing. A programmer who's so lazy as to not put proper error checking in his code, or test it properly, is a bad thing. A lazy programmer who's lazy because he still wants to do loads of stuff, but without the workload, is a good thing.
I'm responsible for building all our assemblies, running unit tests on them and putting them on the correct servers. I'm so lazy that I don't want to do it manually so I set up a continuous integration and automated build system, and now all I have to do is sit back and watch it do all the work.
:)
Admin
Try shopping in New Orleans sometime. I got one for free - no rebates, no coupons, only one crowbar...
Admin
"and I've seen hem spend 20 minutes argueing that he should only pay for a child ticket for the train (and eventually succeeded, mostly because the queue behind him were beginning to look like a mob). "
If I were the ticket inspector I would gave him three options
1º) He is an adult and must pay like it
2º) He isn't one and is travelling with his parents -> that's ok
3º) He isn't one and is not travelling with his parents
3.1º) If he has a note authorizing him to travel alone -> that's ok
3.2º) If he doesn't have it -> I should report the authorities for a possible kidnapping
Admin
Yep, cause that's certainly the reason that the programmer claimed it was technically unfeasable. Not because he couldn't come up with the most obvious (and yes, less desirable) solution (but a solution nonetheless). But because it was loosely coupled. Yep yep.
Admin
WTF?
According to my watch, it's 2006.
Is this a trick question, or something?
Admin
I know one person born on Feb 29, and he adamantly states his age according to the number of "real birthdays" he has had, approximately his real age divided by four.
Tell him he can't drink, vote, drive, get a credit card or loan, watch rated movies or play rated games, and he has to be in bed by 9PM with all his homework done. Until he's something like 230 actual years old...
Admin
Actually if it's based on a factor of 4 then it'd be something like 80-odd. Still worth trying though.
Admin
Assuming the RDBMS supports a MOD function, something like this should do the trick:
<font style="color: rgb(0, 0, 255);" size="1">SELECT CustomerId, EmailAddress
FROM Customers
WHERE
(
DATEPART(day, Birthdate) = DATEPART(day, Today() + 1)
AND DATEPART(month, Birthdate) = DATEPART(month, Today() + 1)
)
OR
(
DATEPART(day, Today()) = 28
AND DATEPART(month, Today()) = 2
AND
(
mod(DATEPART(year, Today()), 4) <> 0
OR
(
mod(DATEPART(year, Today(), 100) = 0
AND mod(DATEPART(year, Today(), 400) <> 0
)
)
and DATEPART(day, Birthdate) == 29
and DATEPART(month, Birthdate) = 2
)
</font>
i.e. Either tomorrow is the customer's birthday or today is February 28th, it's not a leap year, and the customer's birthday is the 29th.
Considering this code is unlikely to still be in use in the year 2100, it can simplified to:
<font style="color: rgb(0, 0, 255);" size="1">SELECT CustomerId, EmailAddress
FROM Customers
WHERE
(
DATEPART(day, Birthdate) = DATEPART(day, Today() + 1)
AND DATEPART(month, Birthdate) = DATEPART(month, Today() + 1)
)
OR
(
DATEPART(day, Today()) = 28
and DATEPART(month, Today()) = 2
</font><font style="color: rgb(0, 0, 255);" size="1"> -- will not work properly in years divisible by 100.
</font><font style="color: rgb(0, 0, 255);" size="1"> and mod(DATEPART(year, Today()), 4) <> 0
and DATEPART(day, Birthdate) == 29
and DATEPART(month, Birthdate) = 2
)</font>
Alternatively, you could write a function that takes a birthday and returns the day to send the card (based on the business rules implied in the original queries: the day before the birthday or the 28th if it's not a leap year and the customer's bday is 2/29) and then rewrite the query as:
<font style="color: rgb(0, 0, 255);" size="1">SELECT CustomerId, EmailAddress
FROM Customers
WHERE
</font><font style="color: rgb(0, 0, 255);" size="1">dayToSendCard(Birthdate) = </font><font style="color: rgb(0, 0, 255);" size="1">trunc(Today())
</font>In Oracle, Trunc(<date>) strips off the hours and minutes . i.e. It returns a timestamp equivalent to midnight of the passed in date. You need to truncate the date or the code will only work if you run at EXACTLY midnight. Substitute trunc for whatever method is used by this RDBMS to accomplish the same thing.
<font style="color: rgb(0, 0, 255);" size="1"></font>
Or you can tell the client that it's technically impossible. If your clients can be placated by telling them that, then they probably getting what they deserve. Why bother implementing anything when the company is doomed to fail.
Admin
You're assuming that the coupon is only good on their birthday?
Admin
AAAHHH!!! NOOOOOO!!!
</date>
Admin
A crucial factor is deciding whether Frederick is smart enough to realize that 1900 isn't a leap year.
Admin
I would take the approach of a function which determines when your birthday is celebrated.
select ... where will_celebrate_birthday_today( birthdate );
function will celebrate_birthday_today
bmonth = month( birth );
bday = day( birth );
tmonth = month( today );
tday = day( today );
if ( bmonth == 2 ) and ( bday == 29 ) then
# no changes in the case of today being Feb.29
if not ( (tmonth == 2 ) and (tday == 29) ) then
# leap year babies celebrate on Mar.1
bmonth = 3;
bday = 1;
endif
endif
return ( bmonth == tmonth ) and ( bday == tday );
Admin
100th reply!