Reputation: 35
Please help me with the issue . I have tried lot many solution and they are not working .
rd["DOB"].ToString() = "9/19/1946";
DateTime dt1 = DateTime.ParseExact(rd["DOB"].ToString(), "MM/dd/yyyy", System.Globalization.CultureInfo.InvariantCulture);
Upvotes: 0
Views: 343
Reputation: 21
You can refer below URL for more grasp on date time format http://msdn.microsoft.com/en-us/library/az4se3k1.aspx
Upvotes: 2
Reputation: 171914
You should use "M/d/yyyy" as the format string.
MM/dd/yyyy would match 09/19/1946, but not 9/19/1946
Upvotes: 3
Reputation: 4043
Have you tried using the Convert class?
Convert.ToDateTime(rd["DOB"]);
If you are using System.Data.DataRow and the column "DOB" is of type SqlDateTime then that should work.
Upvotes: 1