1

Possible Duplicate:
Convert string to datetime Using C#

I want to convert string to DateTime in .NET 2.0. For example, the string will be in the format like 10/07/2011 (dd/MM/yyyy) and then I want to convert it to DateTime object.

Community
  • 1
  • 1
Aung Chan Myae
  • 159
  • 1
  • 10

2 Answers2

1

You can parse custom string date formats into a DateTime using DateTime.ParseExact. For example:

var dateTime = DateTime.ParseExact(
    "10/07/2011",
    "dd/MM/yyyy",
    CultureInfo.InvariantCulture);

Or you can specify a culture that has a DMY date format, such as the UK:

var dateTime = DateTime.Parse("13/07/2011", new CultureInfo("en-GB"));
Chris Fulstow
  • 41,170
  • 10
  • 86
  • 110
0
DateTime dt = DateTime.Parse(strdate); 
Dirk De Winnaar
  • 167
  • 2
  • 9