Microsoft rang in the new year with a cutesy tweet in C#. Just one problem: The code sucked

When marketing meets coding

Microsoft has ushered in 2022 with an amusing (and now deleted) tweet from its Windows Developer account that answers oh so many questions about the quality of code emitted from Redmond nowadays.

As is so often the case, the code (which looked like it aimed to greet 2022 with a perky "Happy New Year") doesn't appear to have troubled a reviewer before going live. Taking aside the fact that it's going to whinge about it still being 2021 when it isn't, there's also the use of the ToString() method when other properties might well have done the job better. And why the "=="?

Click to enlarge

Still, it's the thought that counts. One should consider oneself fortunate that one's own well-intentioned coding cockups have never plopped out of the social media orifice of a company with a market cap in the trillions.

Memories of having to deal with the frankly barking mad US date format still haunt your correspondent to this very day. And then there were the time zones to worry about...

The tweet attracted the usual barrage of supportive and helpful comments typical of Twitter, including a meme from one of Microsoft's own coding boffins, Scott Hanselman, who later followed up with a useful video he described as "an overly detailed analysis of a bad DateTime comparison in C#."

The video is well worth a watch, not least because it delves into not just the obvious flaws in the code but also other considerations that need to be taken into account when handling dates.

As for the original code... well, at best it'll probably keep insisting it is 2021 aside for one brief second. And let's face it, even that isn't right. As another commenter observed: "Yeah 2021 is wrong. We're still stuck in 2020." ®

Send us news

Microsoft to give more than microsecond's thought about your Windows 11 needs

Concerns over consistent dialog boxes, pinning, default apps mulled

Microsoft pushes out PowerShell scripts to fix BitLocker bypass

Attackers exploiting the vulnerability could access encrypted data

Microsoft adds features to Windows 11 monthly – managing it is your problem

'Continuous innovation' means it's time to refine your WSUS skills unless you want users doing all sorts of weird stuff

Microsoft squashes Windows bug exploited to inflict ransomware misery

Not-so-smart SmartScreen flagged up by Googlers

Google euthanizes Chrome Cleanup Tool because it no longer has a purpose

Times have changed and unwanted software on Windows is a rarity (unless you count Windows itself)

Europe, America fear Twitter job cuts mean it can't protect users

How will Elon conform to FTC decrees and EU laws? He probably doesn't know, either

Microsoft's Copilot AI to pervade the whole 365 suite

Clippy 2.0 to help us 'reconnect with the soul of our work' ... just don't mention that lawsuit

Microsoft: Patch this severe Outlook bug that Russian miscreants exploited

Plus: Fixes for SAP, Adobe. Android, Chrome

Microsoft picks perfect time to dump its AI ethics team

Machine-learning safety and controls now everyone's problem

'Major' news: Microsoft slips Bing chatbot shortcut into Windows 11

Celebrated, unhinged search tool pushed in latest OS update

Sony won't budge on Microsoft-Activision merger objection

Ten-year deal to put Call of Duty on PlayStation shot down

Microsoft pauses delayed partner ecosystem security update to count its money

Active Directory privilege de-escalation will run for nine days in May before taking June off