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: 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

    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

    CVE-2025-7752 – Code-projects Online Appointment Booking System SQL Injection Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Biometrics vs. passcodes: What lawyers recommend if you’re worried about warrantless phone searches

    News & Updates

    CVE-2025-6103 – “WiFi-soft UniBox Controller Os Command Injection Vulnerability”

    Common Vulnerabilities and Exposures (CVEs)

    CVE-2024-40460 – Ocuco Innovation Privilege Escalation Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Highlights

    CVE-2025-5865 – RT-Thread Parameter Handler Memory Corruption Vulnerability

    June 9, 2025

    CVE ID : CVE-2025-5865

    Published : June 9, 2025, 7:15 a.m. | 2 hours, 23 minutes ago

    Description : A vulnerability was found in RT-Thread 5.1.0. It has been rated as critical. Affected by this issue is the function sys_select of the file rt-thread/components/lwp/lwp_syscall.c of the component Parameter Handler. The manipulation of the argument timeout leads to memory corruption. The vendor explains, that “[t]he timeout parameter should be checked to check if it can be accessed correctly in kernel mode and used temporarily in kernel memory.”

    Severity: 8.0 | HIGH

    Visit the link for more details, such as CVSS details, affected products, timeline, and more…

    Mortal Shell 2 was Summer Game Fest’s first banger announcement, and the Soulslike sequel is getting a beta before release

    June 7, 2025

    CVE-2025-54079 – WeGIA SQL Injection Vulnerability

    July 18, 2025

    Distribution Release: PorteuX 2.1

    May 31, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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