Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 583145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:45:43+00:00 2026-05-13T14:45:43+00:00

I work for myself, I am a self-employed coder and as a result I

  • 0

I work for myself, I am a self-employed coder and as a result I don’t have the luxury of code reviews or the ability to improve based upon peer programming. I am going to use this as an exercise to see if the StackOverflow community might help to review a simple method which i’ve written;

    internal static DateTime CONVERT_To_DateTime(int binDate)
    {
        //   3/10/2008 = 1822556159
        //   2/10/2008 = 1822523391
        //   1/10/2008 = 1822490623
        //   30/09/2008 = 1822392319
        //   29/09/2008 = 1822359551

        //   September 30th 2008
        //   1822392319 = 0x6c9f7fff
        //   0x6c = 108 = 2008 (based on 1900 start date)
        //   0x9 = 9 = September
        //   0xf7fff - take top 5 bits = 0x1e = 30

        //   October 1st 2008
        //   1822490623 = 0x6ca0ffff
        //   0 x6c = 108 = 2008
        //   0 xa = 10 = October
        //   0x0ffff  - take top 5 bits = 0x01 = 1

        //   OR using Binary (used by this function)
        //   a = 1822556159 (3/10/2008)
        //   1101100 1010 00011 111111111111111

        //   b = 1822523391 (2/10/2008)
        //   1101100 1010 00010 111111111111111

        //   c = 1822490623 (1/10/2008)
        //   1101100 1010 00001 111111111111111

        //   D = 1822392319 (30/09/2008)
        //   1101100 1001 11110 111111111111111

        //   Excess 111111 are probably used for time/seconds which
        //   we do not care for at the current time

        var BaseYear = 1900;

        //  Dump the long date to binary
        var strBinary = Convert.ToString(binDate);

        //  Calculate the year
        var strBYear = strBinary.Substring(0, 7);
        var iYear = Convert.ToInt32(strBYear, 2) + BaseYear;

        //  Calculate the month
        var strBMonth = strBinary.Substring(7, 4);
        var iMonth = Convert.ToInt32(strBMonth, 2);

        //  Calculate the day
        var strBDay = strBinary.Substring(11, 5);
        var iDay = Convert.ToInt32(strBDay, 2);

        // ensure that month and day have two digits
        var strDay = iDay < 10 ? "0" + iDay : iDay.ToString();
        var strMonth = iMonth < 10 ? "0" + iMonth : iMonth.ToString();

        //  Build the final date
        var convertedDate = iYear + strMonth + strDay;

        return DateTime.ParseExact(convertedDate, "yyyyMMdd", null);
    }

This is a method that takes a numeric representation of a date and converts it to a DateTime DataType. I would like the method to be reviewed to acheive the fastest possible execution time because it’s being executed within a loop.

Any comments on the method is appreciated as this will be an exercise for me. i look forward to some responses.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:45:43+00:00Added an answer on May 13, 2026 at 2:45 pm

    You’re doing string manipulations. This is true performance killer when used in tight loops.

        static DateTime ToDateTime(int value)
        {
            var year = (int)((value & 0xff000000) >> 24);
            var month = (value & 0xf00000) >> 20;
            var day = (value & (0xf8000)) >> 15;
    
            return new DateTime(1900 + year, month, day);
        }
    

    Here’s how you do that. First, take 1822490623 and convert it to binary:

    0110 1100 1010 0000 1111 1111 1111 1111
    

    This is a mask for year:

    f    f    0    0    0    0    0    0 
    

    This is for month:

    0    0    f    0    0    0    0    0
    

    And this is for day:

    0    0    0    f    8    0    0    0
    

    “Year” value has to be shifted right by 6 * 4 bits, “month” – by 5 * 4, and “day” – by 3 * 4 + 3 bits.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found myself doing this in my code to 'cache' the work done
How do recursive ascent parsers work? I have written a recursive descent parser myself
not sure why my code wont work, im teaching myself javascript i know php
I am relatively new to writing in C. I have self taught myself using
I've been driving myself crazy trying to get the Entity Framework to work as
I've recently being trying to teach myself how parsers (for languages/context-free grammars) work, and
I'm prepping for a simple work project and am trying to familiarize myself with
While using Vim (at home and at work), I often find myself doing similar
work on asp.net vs 05 C#.Master page header contain the bellow code <script type=text/javascript
Work on asp.net vs05. I have three type of value Like:IsDesign,IsPrinting,IsInstall they are bit

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.