Converting DOS date to mmddyyyy format in C#

  • Thread starter Thread starter spdude
  • Start date Start date
S

spdude

I am working on an application that stores date in DOS format. For ex:
9540 which appears to be the number of days since 1980. Anyone knows a
way to convert this into the mmddyyyy format?

Thanks in advance.
 
I am working on an application that stores date in DOS format. For ex:
9540 which appears to be the number of days since 1980. Anyone knows a
way to convert this into the mmddyyyy format?

How about

new DateTime(1980, 1, 1).AddDays(yourDateValue).ToString("MMddyyyy");


Mattias
 
Just create a different class with static methods

public class DOSDateTimeFormat
{
public static DateTime ConvertFrom(string dt_value)
{
return new DateTime(1980, 1, 1).AddDays(dt_value);
}

public static string ConvertTo(DateTime dt)
{
return ( dt.Subtract(new DateTime(1980, 1, 1))
).ToString("MMddyyyy");
}
}

That way it can be reusable and you can put the class in a utility
assembly.

Sincerely,
Bobby
 
Does
DateTime.FromOADate( <double> )

do it for you? It takes a date as a double (number of days since...) and
converts it to a DateTime.

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top