Click here to Skip to main content
14,580,625 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.

 
General99 bottles of beer in Malbolge Pin
Brisingr Aerowing29-Jun-20 6:17
professionalBrisingr Aerowing29-Jun-20 6:17 
GeneralHow NOT to calculate the end of month... PinPopular
Rob Grainger15-Jun-20 2:01
MemberRob Grainger15-Jun-20 2:01 
GeneralRe: How NOT to calculate the end of month... Pin
OriginalGriff15-Jun-20 2:38
mveOriginalGriff15-Jun-20 2:38 
Ah.
I can see a problem developing there. I assume he tested it on the first of the month, and it worked fine? Laugh | :laugh:
Here is my stab at it:
/// <summary>
    /// Returns the last day in the current month
    /// </summary>
    /// <example>
    /// DateTime endOfMonth = DateTime.Now.LastDayOfMonth();
    /// </example>
    /// <param name="dt" />Start date
    /// <returns />
    public static DateTime LastOfMonth(this DateTime dt)
        {
        int daysInMonth = DateTime.DaysInMonth(dt.Year, dt.Month);
        return dt.FirstOfMonth().AddDays(daysInMonth - 1).AtMidnight();
        }
As seen before: DateTime Extensions to Make Some Simple Tasks a Little More Readable[^]
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!

GeneralRe: How NOT to calculate the end of month... PinPopular
Rob Grainger15-Jun-20 3:06
MemberRob Grainger15-Jun-20 3:06 
GeneralRe: How NOT to calculate the end of month... Pin
OriginalGriff15-Jun-20 3:10
mveOriginalGriff15-Jun-20 3:10 
GeneralRe: How NOT to calculate the end of month... Pin
0x01AA15-Jun-20 3:19
mve0x01AA15-Jun-20 3:19 
GeneralRe: How NOT to calculate the end of month... Pin
Member 798912215-Jun-20 3:37
MemberMember 798912215-Jun-20 3:37 
GeneralRe: How NOT to calculate the end of month... Pin
0x01AA15-Jun-20 4:00
mve0x01AA15-Jun-20 4:00 
GeneralRe: How NOT to calculate the end of month... Pin
Marc Clifton15-Jun-20 4:59
mvaMarc Clifton15-Jun-20 4:59 
GeneralRe: How NOT to calculate the end of month... Pin
obermd17-Jun-20 4:29
Memberobermd17-Jun-20 4:29 
GeneralRe: How NOT to calculate the end of month... Pin
Myron Dombrowski17-Jun-20 14:21
MemberMyron Dombrowski17-Jun-20 14:21 
GeneralRe: How NOT to calculate the end of month... Pin
EbenRoux16-Jun-20 23:16
MemberEbenRoux16-Jun-20 23:16 
GeneralRe: How NOT to calculate the end of month... Pin
Rob Grainger16-Jun-20 23:32
MemberRob Grainger16-Jun-20 23:32 
GeneralRe: How NOT to calculate the end of month... PinPopular
BDieser17-Jun-20 1:41
MemberBDieser17-Jun-20 1:41 
GeneralRe: How NOT to calculate the end of month... Pin
Rob Grainger17-Jun-20 12:38
MemberRob Grainger17-Jun-20 12:38 
GeneralClient sided login Pin
Brisingr Aerowing25-May-20 12:42
professionalBrisingr Aerowing25-May-20 12:42 
GeneralRe: Client sided login Pin
lw@zi 25-May-20 18:34
professional lw@zi 25-May-20 18:34 
GeneralRe: Client sided login Pin
Sander Rossel25-May-20 19:59
professionalSander Rossel25-May-20 19:59 
GeneralRe: Client sided login Pin
lw@zi 26-May-20 21:29
professional lw@zi 26-May-20 21:29 
GeneralRe: Client sided login Pin
Sander Rossel26-May-20 21:51
professionalSander Rossel26-May-20 21:51 
GeneralRe: Client sided login Pin
Andreas Mertens17-Jun-20 6:22
professionalAndreas Mertens17-Jun-20 6:22 
GeneralRe: Client sided login Pin
DerekT-P28-May-20 6:33
professionalDerekT-P28-May-20 6:33 
GeneralRe: Client sided login Pin
lw@zi 30-May-20 0:36
professional lw@zi 30-May-20 0:36 
GeneralRe: Client sided login Pin
DerekT-P30-May-20 2:18
professionalDerekT-P30-May-20 2:18 
GeneralRe: Client sided login Pin
Kornfeld Eliyahu Peter25-May-20 20:24
mveKornfeld Eliyahu Peter25-May-20 20:24 

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.