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

    CVE-2025-45474 – Maccms SSRF Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-35036 – Apache Hibernate Expression Language Injection Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Windows 11 KB5062553 24H2 big update, direct download links

    Operating Systems

    CVE-2025-46549 – YesWiki Reflected Cross-Site Scripting Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Highlights

    CVE-2025-39389 – Solid Plugins AnalyticsWP SQL Injection

    May 19, 2025

    CVE ID : CVE-2025-39389

    Published : May 19, 2025, 8:15 p.m. | 2 hours, 33 minutes ago

    Description : Improper Neutralization of Special Elements used in an SQL Command (‘SQL Injection’) vulnerability in Solid Plugins AnalyticsWP allows SQL Injection.This issue affects AnalyticsWP: from n/a through 2.1.2.

    Severity: 9.3 | CRITICAL

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

    Finally, a portable laser projector with a battery-powered tripod (and it’s on sale)

    June 12, 2025

    CVE-2025-6566 – Oatpp Oat++ JSON DeserializeArray Stack-Based Buffer Overflow Vulnerability

    June 24, 2025

    Enhancing JSON Responses with Laravel Model Appends

    July 9, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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