Windows Developer Team Tweets a Programming Mistake

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:

Windows Intelligence In Your Inbox

Sign up for our new free newsletter to get three time-saving tips each Friday — and get free copies of Paul Thurrott's Windows 11 and Windows 10 Field Guides (normally $9.99) as a special welcome gift!

"*" indicates required fields

This field is for validation purposes and should be left unchanged.

Run code: Happy New Year

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

else
{
    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.

Share post

Please check our Community Guidelines before commenting

Conversation 19 comments

  • erichk

    Premium Member
    04 January, 2022 - 11:10 am

    <p>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.</p>

  • spiderman2

    04 January, 2022 - 11:14 am

    <p><span style="color: rgb(0, 0, 0);">"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.)"</span></p><p><br></p><ol><li><span style="color: rgb(0, 0, 0);">there is nothing wrong with this</span></li><li><span style="color: rgb(0, 0, 0);">it still runs on all c# projects</span></li><li><span style="color: rgb(0, 0, 0);">this kind of code it’s used for all this type of cases (jokes, ads, greetings, ecc..)</span></li></ol>

  • madthinus

    Premium Member
    04 January, 2022 - 11:20 am

    <p>A programming mistake from the Windows Developer team…are we calling this UWP? </p><p><br></p><p>I will see myself out.</p>

    • wright_is

      Premium Member
      05 January, 2022 - 12:45 am

      <p>No, it was the printing subsystem team, hot off not managing to fix printing zero-day security bugs for 6 months.</p>

    • dftf

      07 January, 2022 - 4:03 pm

      <p>I was expecting at-least one person to say "what was it… the source-code to <em>Windows</em>"!</p>

  • drwindows

    Premium Member
    04 January, 2022 - 11:27 am

    <p>"<span style="color: rgb(0, 0, 0);">Unfortunately, the code doesn’t work"</span></p><p>This is wrong. Code always works. It just doesn’t always deliver the expected result ;-).</p>

    • LT1 Z51

      Premium Member
      04 January, 2022 - 12:46 pm

      <p>Assuming code compiles it always works. If it doesn’t compile it doesn’t work…</p>

  • sykeward

    04 January, 2022 - 11:32 am

    <p>I sincerely hope that some developer delivered this screenshot to PR as a mean joke.</p><p><br></p><p>I’m really hoping.</p>

    • lvthunder

      Premium Member
      04 January, 2022 - 11:43 am

      <p>It’s probably something they did in 5 seconds and didn’t think anyone would take literally.</p>

      • sykeward

        04 January, 2022 - 12:19 pm

        <p>It’s probably code their social media person tried to write themselves using only Microsoft blog posts as a guide</p>

  • tonchek

    04 January, 2022 - 12:50 pm

    <p>It also wouldn’t work properly in most parts of the world… </p>

  • thalter

    Premium Member
    04 January, 2022 - 12:58 pm

    <p>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#). </p>

    • MarkPow

      Premium Member
      04 January, 2022 - 3:25 pm

      <p>I believe it’s written in HNYScript…</p>

  • whistlerpro

    04 January, 2022 - 1:35 pm

    <p>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…</p>

  • anoldamigauser

    Premium Member
    04 January, 2022 - 2:30 pm

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

  • eric_rasmussen

    Premium Member
    04 January, 2022 - 8:09 pm

    <p>They should have at least used &gt;= 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. ?</p>

    • huddie

      Premium Member
      05 January, 2022 - 5:52 am

      <p>Very true re MS Q&amp;A. </p><p><br></p><p>I think the fact that the Windows dev tweeted this apparently without checking it first says a lot about Windows devs.</p>

  • nbplopes

    05 January, 2022 - 3:19 am

    <p>It is meant to run o peoples heads … not the computer.</p><p><br></p><p>For that matter It works as there are even articles written about it :)</p><p><br></p><p>PS: I would not use this code in a computer program though.</p>

  • waethorn

    05 January, 2022 - 4:38 am

    <p>This is what you get when you have no QA.</p>

Windows Intelligence In Your Inbox

Sign up for our new free newsletter to get three time-saving tips each Friday

"*" indicates required fields

This field is for validation purposes and should be left unchanged.

Thurrott © 2024 Thurrott LLC