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.DateTime

    A System.DateTime structure that represents the data value to convert in UTC format, as follows: YYYY-MM-DDTHH:MM:SSZ..

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);

See Also

Reference

SPFieldDateTime Class

SPFieldDateTime Members

GetFieldValueAsText Overload

Microsoft.SharePoint Namespace