简体   繁体   中英

Error while converting string to Datetime

I have string value 7/29/2000 . When I convert it to date time it's giving an error. Error Message: Cannot convert string to Datetime

IFormatProvider provider = new System.Globalization.CultureInfo("en-US", true);
string oldValue = decrypt.Decrypt(dtOldI9Value.Rows[0][column.ColumnName].ToString().Trim());
DateTime dtOldValue = DateTime.Parse(oldValue, provider, System.Globalization.DateTimeStyles.NoCurrentDateDefault);

From the 3 rd line i am getting the value as "7/29/2000". Please help me.

This works:

IFormatProvider provider = new System.Globalization.CultureInfo("en-US", true);
DateTime dtOldValue = DateTime.Parse("07/29/2000", provider, System.Globalization.DateTimeStyles.NoCurrentDateDefault);
Console.WriteLine(dtOldValue);

So there must be something with your decrypt.Decrypt() . Are you sure it doesn't adds characters to oldValue ? Check oldValue.Length , it should be 10.

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