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 8376653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:28:42+00:00 2026-06-09T15:28:42+00:00

I need to convert from a 32 bit Dos Date to a .NET System.DateTime

  • 0

I need to convert from a 32 bit Dos Date to a .NET System.DateTime and back again. I’m using the two routines below, however when I convert them back and forth they are out by a number of seconds. Can anyone see why?

public static DateTime ToDateTime(this int dosDateTime)
{
    var date = (dosDateTime & 0xFFFF0000) >> 16;
    var time = (dosDateTime & 0x0000FFFF);

    var year = (date >> 9) + 1980;
    var month = (date & 0x01e0) >> 5;
    var day =  date & 0x1F;
    var hour = time >> 11;
    var minute = (time & 0x07e0) >> 5;
    var second = (time & 0x1F) * 2;

    return new DateTime((int)year, (int)month, (int)day, (int)hour, (int)minute, (int)second);
}

public static int ToDOSDate(this DateTime dateTime)
{
    var years = dateTime.Year - 1980;
    var months = dateTime.Month;
    var days = dateTime.Day;
    var hours = dateTime.Hour;
    var minutes = dateTime.Minute;
    var seconds = dateTime.Second;

    var date = (years << 9) | (months << 5) | days;
    var time = (hours << 11) | (minutes << 5) | (seconds << 1);

    return (date << 16) | time;
}
  • 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-06-09T15:28:43+00:00Added an answer on June 9, 2026 at 3:28 pm

    In ToDOSDate, the number of seconds needs to be divided by two before being stored in the time variable. (seconds << 1) left shifts, which multiplies seconds by two. Change that to a right bitwise shift ((seconds >> 1)) to divide by two.

    Note that there’s no way to avoid losing a second in ToDOSDate when there are an odd number of seconds in dateTime. The right bit shift to divide seconds by two will always drop the least significant bit.

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

Sidebar

Related Questions

I need to convert a C/C++ double to a 64 bit two's complement, where
I need to convert a bit-field structure from little-endian to big-endia architecture. What is
The situation: I need to convert our current development environment from Windows XP 32-bit to
I need to convert from sqlite2 db to sqlite3, is there any tutorial that
I have problem i need to convert from my Array structure to std::vector<int> ...
I need to convert keys from type string to hash. The name of all
I need to convert data from a spreadsheet into insert statements in SQL. I've
i need to convert this HQL: FROM Appointment a WHERE (a.group==null OR :user MEMBER
I need to be able to convert from a Delphi Real48 to C# double.
I need to convert html files to excel from time to time. There are

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.