Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      CodeSOD: A Unique Way to Primary Key

      July 22, 2025

      BrowserStack launches Figma plugin for detecting accessibility issues in design phase

      July 22, 2025

      Parasoft brings agentic AI to service virtualization in latest release

      July 22, 2025

      Node.js vs. Python for Backend: 7 Reasons C-Level Leaders Choose Node.js Talent

      July 21, 2025

      The best CRM software with email marketing in 2025: Expert tested and reviewed

      July 22, 2025

      This multi-port car charger can power 4 gadgets at once – and it’s surprisingly cheap

      July 22, 2025

      I’m a wearables editor and here are the 7 Pixel Watch 4 rumors I’m most curious about

      July 22, 2025

      8 ways I quickly leveled up my Linux skills – and you can too

      July 22, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      The Intersection of Agile and Accessibility – A Series on Designing for Everyone

      July 22, 2025
      Recent

      The Intersection of Agile and Accessibility – A Series on Designing for Everyone

      July 22, 2025

      Zero Trust & Cybersecurity Mesh: Your Org’s Survival Guide

      July 22, 2025

      Execute Ping Commands and Get Back Structured Data in PHP

      July 22, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      A Tomb Raider composer has been jailed — His legacy overshadowed by $75k+ in loan fraud

      July 22, 2025
      Recent

      A Tomb Raider composer has been jailed — His legacy overshadowed by $75k+ in loan fraud

      July 22, 2025

      “I don’t think I changed his mind” — NVIDIA CEO comments on H20 AI GPU sales resuming in China following a meeting with President Trump

      July 22, 2025

      Galaxy Z Fold 7 review: Six years later — Samsung finally cracks the foldable code

      July 22, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: Exactly a Date

    CodeSOD: Exactly a Date

    May 13, 2025

    Alexandar sends us some C# date handling code. The best thing one can say is that they didn’t reinvent any wheels, but that might be worse, because they used the existing wheels to drive right off a cliff.

    try
    {
        var date = DateTime.ParseExact(member.PubDate.ToString(), "M/d/yyyy h:mm:ss tt", null); 
        objCustomResult.PublishedDate = date;
    }
    catch (Exception datEx)
    {
    }
    

    member.PubDate is a Nullable<DateTime>. So its ToString will return one of two things. If there is a value there, it’ll return the DateTimes value. If it’s null, it’ll just return an empty string. Attempting to parse the empty string will throw an exception, which we helpfully swallow, do nothing about, and leave objCustomResult.PublishedDate in whatever state it was in- I’m going to guess null, but I have no idea.

    Part of this WTF is that they break the advantages of using nullable types- the entire point is to be able to handle null values without having to worry about exceptions getting tossed around. But that’s just a small part.

    The real WTF is taking a DateTime value, turning it into a string, only to parse it back out. But because this is in .NET, it’s more subtle than just the generation of useless strings, because member.PubDate.ToString()‘s return value may change depending on your culture info settings.

    Which sure, this is almost certainly server-side code running on a single server with a well known locale configured. So this probably won’t ever blow up on them, but it’s 100% the kind of thing everyone thinks is fine until the day it’s not.

    The punchline is that ToString allows you to specify the format you want the date formatted in, which means they could have written this:

    var date = DateTime.ParseExact(member.PubDate.ToString("M/d/yyyy h:mm:ss tt"), "M/d/yyyy h:mm:ss tt", null);
    

    But if they did that, I suppose that would have possibly tickled their little grey cells and made them realize how stupid this entire block of code was?

    [Advertisement]
    Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today!

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleCVE-2025-26662 – Apache Data Services Management Console Cross-Site Scripting Vulnerability
    Next Article nip4 is an image processing spreadsheet

    Related Posts

    News & Updates

    The best CRM software with email marketing in 2025: Expert tested and reviewed

    July 22, 2025
    News & Updates

    This multi-port car charger can power 4 gadgets at once – and it’s surprisingly cheap

    July 22, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    Try It On: A Playful Drag-and-Drop Styling UI

    News & Updates

    CVE-2025-45250 – MrDoc SSRF Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    How to Use Wireshark Filters to Analyze Your Network Traffic

    Development

    How to Watch Pornhub in South Carolina: A Step-by-Step Guide

    Operating Systems

    Highlights

    News & Updates

    “PS5 makes the most sense at the moment.” Ori dev suggests ‘No Rest for the Wicked’ will skip Xbox (for launch) due to “market conditions.”

    July 22, 2025

    Moon Studios’ next title “No Rest for the Wicked” might skip Xbox at launch, with…

    CVE-2025-53381 – Apache HTTP Server Unvalidated User Input

    June 28, 2025

    CatOS is an open-source Arch-based out-of-the-box Linux distribution

    May 7, 2025

    CVE-2025-45956 – Sourcecodester Computer Laboratory Management System SQL Injection

    April 29, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.