I am fetching list date item in string variable then I want to insert it in SQL table, but in SQL the column type is DateTime. So I need to convert string to DateTime.
I am using below code:
DateTime strAllocatedOn;
string[] format = { "dd/MM/yyyy HH:mm:ss tt", "dd-MM-yyyy HH:mm:ss tt" };
DateTime.TryParseExact(dt.Rows[j]["Created"].ToString(), format, null, DateTimeStyles.None, out strAllocatedOn);
But getting below error:
An error occurred during the compilation of the requested file, or one of its dependencies. Invalid expression term 'out'
Date format which I am receving is "10/3/2011 4:38:27 PM".
The formats you're giving don't match the sample value you've provided:
Leaving the space issue aside, I suspect you want
d-M-yyyy h:mm:ss tt
d/M/yyyy h:mm:ss tt
as the valid formats.
(See custom date and time format strings in MSDN for more information.)
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.