Click here to Skip to main content
15,899,754 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.

 
GeneralThis really happened Pin
Zani Jnior8-Jun-08 2:08
Zani Jnior8-Jun-08 2:08 
GeneralRe: This really happened Pin
leppie8-Jun-08 2:36
leppie8-Jun-08 2:36 
GeneralRe: This really happened Pin
Zani Jnior8-Jun-08 2:42
Zani Jnior8-Jun-08 2:42 
GeneralRe: This really happened Pin
leppie8-Jun-08 2:45
leppie8-Jun-08 2:45 
GeneralRe: This really happened Pin
Rick York9-Jun-08 21:19
mveRick York9-Jun-08 21:19 
GeneralRe: This really happened Pin
Megidolaon18-Jun-08 3:52
Megidolaon18-Jun-08 3:52 
GeneralRe: This really happened Pin
Paul Conrad2-Jul-08 19:55
professionalPaul Conrad2-Jul-08 19:55 
GeneralDateTime truncation Pin
PIEBALDconsult5-Jun-08 18:28
mvePIEBALDconsult5-Jun-08 18:28 
Today I had to write something I consider a horror. It's very much like some similarly bad code that's been exposed here, but no other solution came immediately to mind... and it works. Big Grin | :-D

Without going into detail, I have a form that dynamically creates its controls according to an XML document.
So, if the document specifies "System.DateTime" a DateTimePicker will be instantiated and added to the form.
I also decided to add the ability to control the format via the XML, by setting the CustomFormat property.

All is well and good.

Today I was writing one of these XML documents and needed a DateTime with format "yyyy-MM-dd", simple enough, works great.
Until I realized that I also needed to truncate the DateTime (zero-out the time-of-day part in this case).

Truncating a DateTime is no big deal; I even wrote a (poorly-received) article[^] on it.
But that solution won't work well in this case; I wanted a way to truncate based on the provided format.


After a little thought I had the solution, but it feels so dirty: Unsure | :~

mydate = System.DateTime.ParseExact ( mydate.ToString ( format ) , format , null ) ;


I haven't tested it extensively; I'm afraid of what I might find.
GeneralRe: DateTime truncation Pin
Mladen Janković6-Jun-08 2:23
Mladen Janković6-Jun-08 2:23 
GeneralRe: DateTime truncation Pin
leppie6-Jun-08 2:28
leppie6-Jun-08 2:28 
GeneralRe: DateTime truncation Pin
PIEBALDconsult6-Jun-08 5:07
mvePIEBALDconsult6-Jun-08 5:07 
GeneralRe: DateTime truncation Pin
Megidolaon11-Jun-08 2:15
Megidolaon11-Jun-08 2:15 
GeneralRe: DateTime truncation Pin
#realJSOP10-Jun-08 6:45
professional#realJSOP10-Jun-08 6:45 
GeneralRe: DateTime truncation Pin
PIEBALDconsult10-Jun-08 14:01
mvePIEBALDconsult10-Jun-08 14:01 
GeneralHuh... that's odd... Pin
PIEBALDconsult3-Jun-08 5:10
mvePIEBALDconsult3-Jun-08 5:10 
GeneralRe: Huh... that's odd... Pin
CPallini3-Jun-08 6:27
mveCPallini3-Jun-08 6:27 
GeneralRe: Huh... that's odd... Pin
leppie3-Jun-08 9:26
leppie3-Jun-08 9:26 
JokeRe: Huh... that's odd... Pin
Yusuf3-Jun-08 9:44
Yusuf3-Jun-08 9:44 
GeneralRe: Huh... that's odd... Pin
CDP18024-Jun-08 0:09
CDP18024-Jun-08 0:09 
GeneralRe: Huh... that's odd... Pin
Yusuf4-Jun-08 3:23
Yusuf4-Jun-08 3:23 
GeneralRe: Huh... that's odd... Pin
MarkB7775-Jun-08 22:26
MarkB7775-Jun-08 22:26 
GeneralRe: Huh... that's odd... Pin
Nelek7-Jun-08 2:46
protectorNelek7-Jun-08 2:46 
GeneralRe: Huh... that's odd... Pin
megaadam3-Jun-08 22:26
professionalmegaadam3-Jun-08 22:26 
GeneralRe: Huh... that's odd... Pin
CPallini3-Jun-08 23:42
mveCPallini3-Jun-08 23:42 
GeneralRe: Huh... that's odd... Pin
CDP18023-Jun-08 23:22
CDP18023-Jun-08 23:22 

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.