简体   繁体   中英

DateTime in sharepoint 2007

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:

  • There are spaces around the value you've provided; are they in the real data? Consider trimming
  • Your value has "3" as the month number, which is valid for "M" but not "MM"
  • Your vlaue has "4" as the hour number, which is valid for "h" but not "HH" (it's rare to use HH in conjunction with tt)

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.

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