Reputation: 47
I am a bit lost and need your help, this seems to be easy in PHP but I am new to C#.
I have a string
string str = "41305"; // equivalent to 01/31/2013, parse from excel reader.
I need to insert date in DBF file and I am getting mismatch data type. How can I format it to DateTime ISO Format 20130131? Thanks in Advance.
Upvotes: 0
Views: 535
Reputation: 223247
Use DateTime.FromOADate method.
DateTime dt = DateTime.FromOADate(41305);
For output:
Console.WriteLine(dt.ToString("MM/dd/yyyyy"));
Output would be:
01/31/02013
Since you have the value in string, you can parse it to double using Double.Parse
or Double.TryParse
according to your requirement.
EDIT: Like:
string str = "41305";
DateTime dt = DateTime.FromOADate(double.Parse(str));
Upvotes: 6
Reputation: 10422
string str = "41305";
DateTime d = DateTime.FromOADate(Convert.ToDouble(str));
Upvotes: 1