Sharepoint DateTime Column CAML Query

This is a quick post on how to search SharePoint DateTime column using incorporating a DateTime object inside a CAML query.

CAML is Collaborative Application Markup Language is a XML based language that can be used by developers to build, customise and query web sites in SharePoint Services.

You can use SPUtility.CreateISO8601DateTimeFromSystemDateTime to ensure the DateTime object passed by you is in the format acceptable by SharePoint.

Dim CurrDate As String = SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.Now)
Dim _Qry As SPQuery = New SPQuery
_Qry.Query = "<Where>" & _
                "<Eq>" & _
                 "<FieldRef Name='Published_x0020_Date' />" & _
                 "<Value Type='Datetime'>" & CurrDate & "</Value>" & _
               "</Eq>" & _

In the code above, I have used a CAML query to find if Published Date column has today’s date. To use SPUtility the following needs to be added

Imports Microsoft.Sharepoint.Utilities

You can also use it like.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s