Click here to Skip to main content
15,887,350 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: Anagram finder Pin
dawmail33316-Sep-09 2:11
dawmail33316-Sep-09 2:11 
GeneralRe: Anagram finder Pin
dojohansen15-Oct-09 1:25
dojohansen15-Oct-09 1:25 
GeneralHow to group by hour properly. [modified] Pin
Brady Kelly20-Aug-09 22:33
Brady Kelly20-Aug-09 22:33 
GeneralRe: How to group by hour properly. Pin
David Skelly21-Aug-09 0:49
David Skelly21-Aug-09 0:49 
GeneralRe: How to group by hour properly. Pin
Brady Kelly21-Aug-09 0:53
Brady Kelly21-Aug-09 0:53 
GeneralRe: How to group by hour properly. Pin
ClementsDan21-Aug-09 15:22
ClementsDan21-Aug-09 15:22 
GeneralRe: How to group by hour properly. Pin
MaksimP25-Sep-09 10:07
MaksimP25-Sep-09 10:07 
GeneralHow to handle dates _properly_. [modified] Pin
Brady Kelly20-Aug-09 12:31
Brady Kelly20-Aug-09 12:31 
First, you use a varchar(20) default '' to store a six char date in the form yymmdd.  Users have the luxury of an extra fourteen chars to add willy nilly romantic annotations to the date.  Savvy data entry clerks may even squeeze a well formed XHTML tag in there.

Then, when the huns appear over the next control-break horizon, and you need the real DateTime you promised them, you divide and conquer.  A bunch of little two character numbers quickly evaporate into two character numbers.  Except the year pair, '09'.  In the shocking assault on decency everywhere, teh geinus grugru of date parsing expertly recognised that the '09' needed '20'.  Why waste two innocent zeros and add '2000', when you can add '20', as in string conctratingation, but hey, strings are for physicists and yoyos, so lets just add 20. 

In the following horrific, true life example of unprecedented savagery, our valiant knight takes a string value for detailLastDate; of '090722' and with a wave of a hanky and quickly stuffing a rabbit into a hat for distraction, presents The Date Parsing canon (emphasis mine):
DateTime time2 = new DateTime(int.Parse(20 + detailLastDate.Substring(0, 2)), int.Parse(detailLastDate.Substring(2, 2)), int.Parse(detailLastDate.Substring(4, 2)));

Isn't it wonderful how he can just add the integer 20 to the substring '09', and get a year value of 2009?  I am forever in awe.




Last modified: 9hrs 10mins after originally posted --



GeneralRe: How to handle dates _properly_. Pin
Keith Barrow20-Aug-09 23:03
professionalKeith Barrow20-Aug-09 23:03 
GeneralRe: How to handle dates _properly_. Pin
supercat921-Aug-09 10:14
supercat921-Aug-09 10:14 
GeneralRe: How to handle dates _properly_. Pin
Dan Neely21-Aug-09 10:41
Dan Neely21-Aug-09 10:41 
GeneralRe: How to handle dates _properly_. Pin
supercat924-Aug-09 11:05
supercat924-Aug-09 11:05 
GeneralRe: How to handle dates _properly_. Pin
ClementsDan21-Aug-09 15:38
ClementsDan21-Aug-09 15:38 
GeneralRe: How to handle dates _properly_. [modified] Pin
Vozzie224-Aug-09 16:15
Vozzie224-Aug-09 16:15 
GeneralPractically The Entire Article Pin
Rick York17-Aug-09 6:19
mveRick York17-Aug-09 6:19 
GeneralHow to get today's date PinPopular
Keith Barrow14-Aug-09 0:26
professionalKeith Barrow14-Aug-09 0:26 
GeneralRe: How to get today's date Pin
Nelson Costa Inácio14-Aug-09 1:49
Nelson Costa Inácio14-Aug-09 1:49 
GeneralRe: How to get today's date Pin
MaksimP25-Sep-09 9:55
MaksimP25-Sep-09 9:55 
GeneralRe: How to get today's date Pin
David Skelly14-Aug-09 2:49
David Skelly14-Aug-09 2:49 
GeneralRe: How to get today's date Pin
Keith Barrow14-Aug-09 3:20
professionalKeith Barrow14-Aug-09 3:20 
GeneralRe: How to get today's date Pin
Luc Pattyn14-Aug-09 3:41
sitebuilderLuc Pattyn14-Aug-09 3:41 
GeneralRe: How to get today's date Pin
David Skelly14-Aug-09 5:24
David Skelly14-Aug-09 5:24 
GeneralRe: How to get today's date Pin
David Skelly14-Aug-09 5:06
David Skelly14-Aug-09 5:06 
GeneralRe: How to get today's date Pin
dojohansen15-Oct-09 2:53
dojohansen15-Oct-09 2:53 
GeneralRe: How to get today's date Pin
Carl B. Johnson16-Aug-09 14:27
Carl B. Johnson16-Aug-09 14:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.