简体   繁体   中英

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);

You should use "M/d/yyyy" as the format string.

MM/dd/yyyy would match 09/19/1946, but not 9/19/1946

您可以在下面的URL中引用,以进一步了解日期时间格式http://msdn.microsoft.com/zh-cn/library/az4se3k1.aspx

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM