Reputation: 1252
I have a date time item in a list that I want to interact with. I access the items in the list via SPListItem.
My code:
_relevantDate = (DateTime)_siteInfo["cimKeyDocumentDate"];
What the code means in terms of types etc:
[datetime property] = [datetime cast]SPListItem[field name];
I'm aware of the SPFieldDateTime type but I can't see a type it returns and I am confused at how I should do return the datetime.
Thanks.
Upvotes: 0
Views: 116
Reputation: 4598
Your first code would return datetime
type after correct casting.
DateTime myDateTime = DateTime.Parse(myListItem["MyDateField"].ToString());
but if you want to use SPFieldDateTime
then you will have to write it like
SPFieldDateTime myDateTime =(SPFieldDateTime)web.Fields[FieldNames.DateFieldName];
This will return a field that contains date and time values.See here.
Upvotes: 1