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

      Upwork Freelancers vs Dedicated React.js Teams: What’s Better for Your Project in 2025?

      August 1, 2025

      Is Agile dead in the age of AI?

      August 1, 2025

      Top 15 Enterprise Use Cases That Justify Hiring Node.js Developers in 2025

      July 31, 2025

      The Core Model: Start FROM The Answer, Not WITH The Solution

      July 31, 2025

      Finally, a sleek gaming laptop I can take to the office (without sacrificing power)

      August 1, 2025

      These jobs face the highest risk of AI takeover, according to Microsoft

      August 1, 2025

      Apple’s tariff costs and iPhone sales are soaring – how long until device prices are too?

      August 1, 2025

      5 ways to successfully integrate AI agents into your workplace

      August 1, 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

      Enhancing Laravel Queries with Reusable Scope Patterns

      August 1, 2025
      Recent

      Enhancing Laravel Queries with Reusable Scope Patterns

      August 1, 2025

      Everything We Know About Livewire 4

      August 1, 2025

      Everything We Know About Livewire 4

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

      YouTube wants to use AI to treat “teens as teens and adults as adults” — with the most age-appropriate experiences and protections

      August 1, 2025
      Recent

      YouTube wants to use AI to treat “teens as teens and adults as adults” — with the most age-appropriate experiences and protections

      August 1, 2025

      Sam Altman is afraid of OpenAI’s GPT-5 creation — “The Manhattan Project feels very fast, like there are no adults in the room”

      August 1, 2025

      9 new features that arrived on the Windows 11 Insider Program during the second half of July 2025

      August 1, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: A Second Date

    CodeSOD: A Second Date

    June 17, 2025

    Ah, bad date handling. We’ve all seen it. We all know it. So when Lorenzo sent us this C# function, we almost ignored it:

    private string GetTimeStamp(DateTime param)
    {
        string retDate = param.Year.ToString() + "-";
        if (param.Month < 10)
            retDate = retDate + "0" + param.Month.ToString() + "-";
        else
            retDate = retDate + param.Month.ToString() + "-";
    
        if (param.Day < 10)
            retDate = retDate + "0" + param.Day.ToString() + " ";
        else
            retDate = retDate + param.Day.ToString() + " ";
    
        if (param.Hour < 10)
            retDate = retDate + "0" + param.Hour.ToString() + ":";
        else
            retDate = retDate + param.Hour.ToString() + ":";
    
        if (param.Minute < 10)
            retDate = retDate + "0" + param.Minute.ToString() + ":";
        else
            retDate = retDate + param.Minute.ToString() + ":";
    
        if (param.Second < 10)
            retDate = retDate + "0" + param.Second.ToString() + ".";
        else
            retDate = retDate + param.Second.ToString() + ".";
    
        if (param.Millisecond < 10)
            retDate = retDate + "0" + param.Millisecond.ToString();
        else
            retDate = retDate + param.Millisecond.ToString();
    
        return retDate;
    }
    

    Most of this function isn’t terribly exciting. We’ve seen this kind of bad code before, but even when we see a repeat like this, there are still special treats in it. Look at the section for handling milliseconds: if the number is less than 10, they pad it with a leading zero. Just the one, though. One leading zero should be enough for everybody.

    But that’s not the thing that makes this code special. You see, there’s another function worth looking at:

    private string FileTimeStamp(DateTime param)
    {
        string retDate = param.Year.ToString() + "-";
        if (param.Month < 10)
            retDate = retDate + "0" + param.Month.ToString() + "-";
        else
            retDate = retDate + param.Month.ToString() + "-";
    
        if (param.Day < 10)
            retDate = retDate + "0" + param.Day.ToString() + " ";
        else
            retDate = retDate + param.Day.ToString() + " ";
    
        if (param.Hour < 10)
            retDate = retDate + "0" + param.Hour.ToString() + ":";
        else
            retDate = retDate + param.Hour.ToString() + ":";
    
        if (param.Minute < 10)
            retDate = retDate + "0" + param.Minute.ToString() + ":";
        else
            retDate = retDate + param.Minute.ToString() + ":";
    
        if (param.Second < 10)
            retDate = retDate + "0" + param.Second.ToString() + ".";
        else
            retDate = retDate + param.Second.ToString() + ".";
    
        if (param.Millisecond < 10)
            retDate = retDate + "0" + param.Millisecond.ToString();
        else
            retDate = retDate + param.Millisecond.ToString();
    
        return retDate;
    }
    

    Not only did they fail to learn the built-in functions for formatting dates, they forgot about the functions they wrote for formatting dates, and just wrote (or realistically, copy/pasted?) the same function twice.

    At least both versions have the same bug with milliseconds. I don’t know if I could handle it if they were inconsistent about that.

    [Advertisement] Picking up NuGet is easy. Getting good at it takes time. Download our guide to learn the best practice of NuGet for the Enterprise.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleTeam46 (TaxOff) Exploits Google Chrome Zero-Day (CVE-2025-2783) in Sophisticated Phishing Campaign
    Next Article Haiku OS: Sistema Operativo Libero e Innovativo Avanza

    Related Posts

    News & Updates

    Finally, a sleek gaming laptop I can take to the office (without sacrificing power)

    August 1, 2025
    News & Updates

    These jobs face the highest risk of AI takeover, according to Microsoft

    August 1, 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

    Microsoft clarifies Windows 10 extended updates still work if Windows 11 is unsupported

    Operating Systems

    CVE-2025-4155 – PHPGurukul Boat Booking System SQL Injection Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    I replaced my Galaxy S25 Plus with the S25 Edge (and Samsung may do the same)

    News & Updates

    5 Best Online Claw Machine Games: Real Machines, Real Prizes, Real Fun

    Operating Systems

    Highlights

    News & Updates

    I wish I’d found this Atomfall weapon sooner, it shreds EVERYTHING — trust me, you need to get it

    April 1, 2025

    If you’re more of a ranged combat Atomfall player, then you simply have to get…

    A Coding Guide to Compare Three Stability AI Diffusion Models (v1.5, v2-Base & SD3-Medium) Diffusion Capabilities Side-by-Side in Google Colab Using Gradio

    May 5, 2025

    CVE-2025-40723 – Flatboard Pro Stored Cross-Site Scripting (XSS)

    July 3, 2025

    CVE-2025-2092 – Checkmk GmbH Checkmk Log File Information Disclosure

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

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