Windows Developer Team Tweets a Programming Mistake

Posted on January 4, 2022 by Paul Thurrott in Dev, Windows 10, Windows 11 with 19 Comments

Image credit: Davor Pihač

The Windows Developer team wanted to celebrate the New Year by tweeting some software code to its followers. Unfortunately, the code doesn’t work. And this despite the incredibly basic nature of the code.

I don’t want to spend too much time on this. But it is kind of funny.

On Monday, the official Windows Developer account on Twitter tweeted the following:

Run code: Happy New Year

if (DateTime.Now.ToString() == "01/01/2022 00:00:00")
    Console.WriteLine("Happy New Year!");

    Console.WriteLine("It\'s still 2021...");

That’s C# console code, if you’re not familiar. (And it’s kind of weird that Windows Developer would tweet console code, but whatever.)

Even a non-programmer should be able to tell what the code is trying to do: If you run this app when it’s exactly midnight on New Year’s Eve, you’ll get a “Happy New Year!” message. But if you run it at any other time, it will tell you that it’s still 2021.

So what’s the problem? As it turns out, there are all kinds of issues with this code. But the two biggest and most obvious blunders that I see are:

1. You will only get the New Year greeting at exactly midnight. And I mean exactly. If it is one second into 2022 or one second before 2022, you will not get this greeting.

2. If it’s not exactly midnight, the app will tell you that it’s still 2021. But it will do that no matter what the date or time is. It’s 2022 now, for example, but this app will tell you that it’s 2021.

Realizing its error, the Windows Developer team deleted the tweet. But thanks to Davor Pihač for capturing a screenshot and pointing it in my direction. He also pointed out that this code will only work in the United States because of the way it uses ToString() to make the date/time conversion. Basically, dates are a type and you should never compare dates using strings.

And if you’re really interested in this mess, check out Scott Hanselman’s overly-detailed analysis of the many problems with this code. I was originally going to publish a corrected version of the code myself, but Scott has this covered nicely.

Ah well. All we can do now is laugh.

Join the discussion!


Don't have a login but want to join the conversation? Become a Thurrott Premium or Basic User to participate

Comments (19)

19 responses to “Windows Developer Team Tweets a Programming Mistake”

  1. erichk

    I suppose if we put this code inside of a loop and ran it just before the stroke of midnight, you would really quickly see the Happy New Year greeting scroll by, but you'd really have to pay attention.

  2. tonchek

    It also wouldn't work properly in most parts of the world...

  3. nbplopes

    It is meant to run o peoples heads … not the computer.

    For that matter It works as there are even articles written about it :)

    PS: I would not use this code in a computer program though.

  4. eric_rasmussen

    They should have at least used >= instead of ==, but whatever. It just goes to show that no matter how simple or how short a program is, it's easy to have a bug. Microsoft should not have fired their QA teams. 🤔

    • huddie

      Very true re MS Q&A.

      I think the fact that the Windows dev tweeted this apparently without checking it first says a lot about Windows devs.

  5. anoldamigauser

    From the people responsible for the Y2K22 but in Exchange. The new year must be a hard computer science problem.

  6. whistlerpro

    Does this explain why I only get my 300XP for playing a Halo Infinite multiplayer match once it’s gone midnight in Seattle? Definitely not running to local time…

  7. thalter

    This looks like it was written by a JavaScript programmer with a limited understanding of C#, with the poor handling of types (comparing using strings), and the unnecessary escaping of the single quote character (apostrophe delimited strings are legal in JavaScript, but not C#).

  8. spiderman2

    "That’s C# console code, if you’re not familiar. (And it’s kind of weird that Windows Developer would tweet console code, but whatever.)"

    1. there is nothing wrong with this
    2. it still runs on all c# projects
    3. this kind of code it's used for all this type of cases (jokes, ads, greetings, ecc..)
  9. sykeward

    I sincerely hope that some developer delivered this screenshot to PR as a mean joke.

    I’m really hoping.

  10. drwindows

    "Unfortunately, the code doesn’t work"

    This is wrong. Code always works. It just doesn't always deliver the expected result ;-).

  11. madthinus

    A programming mistake from the Windows Developer team...are we calling this UWP?

    I will see myself out.

  12. waethorn

    This is what you get when you have no QA.

Leave a Reply