SPFieldDateTime.GetFieldValueAsText Method (DateTime, SPWeb, SPDateFormat)
Returns the specified field data value, expressed in Coordinated Universal Time (UTC) format, as a string based on the specified date and time value, parent Web site, and SharePoint Foundation date format.
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
Syntax
'Declaration
Public Shared Function GetFieldValueAsText ( _
data As DateTime, _
web As SPWeb, _
dateformat As SPDateFormat _
) As String
'Usage
Dim data As DateTime
Dim web As SPWeb
Dim dateformat As SPDateFormat
Dim returnValue As String
returnValue = SPFieldDateTime.GetFieldValueAsText(data, _
web, dateformat)
public static string GetFieldValueAsText(
DateTime data,
SPWeb web,
SPDateFormat dateformat
)
Parameters
data
Type: System.DateTimeA System.DateTime structure that represents the data value to convert in UTC format, as follows: YYYY-MM-DDTHH:MM:SSZ..
web
Type: Microsoft.SharePoint.SPWebAn SPWeb
object that represents the Web site that contains the field.
dateformat
Type: Microsoft.SharePoint.Utilities.SPDateFormatAn SPDateFormat value that specifies the date format.
Return Value
Type: System.String
A string that contains the field data value.
Remarks
The GetFieldValueAsText method requires that date and time values be in UTC format, while most SharePoint Foundation methods for returning list data return the values in local time. Consequently, when performing queries for list data, you need to convert time values to get expected results. To return items in UTC date and time, use an SPQuery object and set the DatesInUtc property to true, as seen in the following example:
Dim query As New SPQuery()
query.DatesInUtc = true
Dim listItems As SPListItemCollection = list.GetItems(query)
SPQuery query = new SPQuery();
query.DatesInUtc = true;
SPListItemCollection listItems = list.GetItems(query);