user1448912
user1448912

Reputation: 35

String was not recognized as a valid DateTime

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

Answers (3)

Anand K awasthi
Anand K awasthi

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

Philippe Leybaert
Philippe Leybaert

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

Lawrence Johnson
Lawrence Johnson

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

Related Questions