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

      Sunshine And March Vibes (2025 Wallpapers Edition)

      June 1, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      June 1, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      June 1, 2025

      How To Prevent WordPress SQL Injection Attacks

      June 1, 2025

      7 MagSafe accessories that I recommend every iPhone user should have

      June 1, 2025

      I replaced my Kindle with an iPad Mini as my ebook reader – 8 reasons why I don’t regret it

      June 1, 2025

      Windows 11 version 25H2: Everything you need to know about Microsoft’s next OS release

      May 31, 2025

      Elden Ring Nightreign already has a duos Seamless Co-op mod from the creator of the beloved original, and it’ll be “expanded on in the future”

      May 31, 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

      Student Record Android App using SQLite

      June 1, 2025
      Recent

      Student Record Android App using SQLite

      June 1, 2025

      When Array uses less memory than Uint8Array (in V8)

      June 1, 2025

      Laravel 12 Starter Kits: Definite Guide Which to Choose

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

      Photobooth is photobooth software for the Raspberry Pi and PC

      June 1, 2025
      Recent

      Photobooth is photobooth software for the Raspberry Pi and PC

      June 1, 2025

      Le notizie minori del mondo GNU/Linux e dintorni della settimana nr 22/2025

      June 1, 2025

      Rilasciata PorteuX 2.1: Novità e Approfondimenti sulla Distribuzione GNU/Linux Portatile Basata su Slackware

      June 1, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: Halfway to a Date

    CodeSOD: Halfway to a Date

    January 16, 2025

    Roger took on a contract to fix up a PHP website. During the negotiations, he asked some questions about the design, like, “Is it object-oriented or more procedural?” “No, it’s PHP,” said the developer.

    Which about sums it up, I suppose. Have some date handling code:

    function MnameToMnumber($mname) //takes month name 'January' and returns month number '01'
            {
            if($mname == 'January'){$mnum = '01';}
            elseif($mname == 'February'){$mnum = '02';}
            elseif($mname == 'March'){$mnum = '03';}
            elseif($mname == 'April'){$mnum = '04';}
            elseif($mname == 'May'){$mnum = '05';}
            elseif($mname == 'June'){$mnum = '06';}
            elseif($mname == 'July'){$mnum = '07';}
            elseif($mname == 'August'){$mnum = '08';}
            elseif($mname == 'September'){$mnum = '09';}
            elseif($mname == 'October'){$mnum = '10';}
            elseif($mname == 'November'){$mnum = '11';}
            elseif($mname == 'December'){$mnum = '12';}
            return $mnum;
            }
    
    function MnumberToMname($mname) //takes month number '01' and returns month name '01'
            {
            if($mnum= '01'){$mname = 'January';}
            elseif($mnum= '02'){$mname = 'February';}
            elseif($mnum= '03'){$mname = 'March';}
            elseif($mname == 'April'){$mnum = '04';}
            elseif($mnum= '05'){$mname = 'May';}
            elseif($mnum= '06'){$mname = 'June';}
            elseif($mnum= '07'){$mname = 'July';}
            elseif($mnum= '08'){$mname = 'August';}
            elseif($mnum= '09'){$mname = 'September';}
            elseif($mnum= '10'){$mname = 'October';}
            elseif($mnum= '11'){$mname = 'November';}
            elseif($mnum= '12'){$mname = 'December';}
            return $mname;
            }
    
    

    So, for starters, I “love” the use of Whitesmiths indenting. I don’t think I’ve seen this in the wild. (I predict the comments section will be links to articles where I have seen this in the wild).

    Hostinger

    Beyond that, there’s nothing terribly surprising here, in terms of bad date handling code, with a few small exceptions. First is their insistence on the conversion itself being stringly typed: January isn’t month 1, but "01".

    But more notable: MnumberToMname just doesn’t work. They’re using the assignment operator instead of the equality operator. At least, for all the cases where they’re doing the correct comparison direction. A stray “name to number” conversion is lurking in April. Not that it matters- this will always return January.

    [Advertisement]
    Keep the plebs out of prod. Restrict NuGet feed privileges with ProGet. Learn more.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleFOSS Weekly #25.03: Mint 22.1 Released, AI in VLC, Dual Boot Myths, Torvalds’ Guitar Offer and More
    Next Article Bit – modernized git CLI

    Related Posts

    News & Updates

    7 MagSafe accessories that I recommend every iPhone user should have

    June 1, 2025
    News & Updates

    I replaced my Kindle with an iPad Mini as my ebook reader – 8 reasons why I don’t regret it

    June 1, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Yahoo’s New AI-Driven News App: A Revolution in Digital Journalism

    Artificial Intelligence

    How to use the Photos app on your iPhone with iOS 18

    Development

    7 Essential Logseq Plugins I Use and Recommend

    Linux

    Ma che gli fa il software open-source alle isole? Non si sa, ma Cipro e Trinidad e Tobago sono esempi da seguire!

    Linux
    GetResponse

    Highlights

    News & Updates

    Grand Theft Auto 6 is still slated for Fall 2025, says Take-Two Interactive CEO

    February 6, 2025

    As part of Take-Two Interactive’s Q3 2025 financial results, CEO Strauss Zelnick noted that Grand…

    Harper – English grammar checker

    February 23, 2025

    fEASTback Model: Optimizing Feedback with a Behavioral Perspective

    May 7, 2024

    Is your Microsoft account passwordless yet? Why it (probably) should be and how to do it right

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

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