I am creating a simple form by "Insert Data View" web part and filtering on the data source by date.
Something like: Displays all the announcement items that have:
"Expires"
Greater Than Or Equal
[Current Date]
This seem easy by using the filter task of the Data form Web Part
.
I didn't even look back until some body complains the announcements for today does not seem to appears as expected.
Turn out the [Current Date]
variable I was selecting comes from a CAMLVariable
named Today
, which when printed out is local time.
This, when compare with the Expires
date column, which when printed out is Zulu time.
Obviously, the Expires
and Current Date
, when compared will be off by however many hours the local time is compared to Zulu time.
To get around this issue, I can't have to use a different parameter for comparison, one that is correct today Zulu time.
I created an ASP.NET web control to output the today Zulu time, which then will be used as parameter to the Data form Web Part
filter.
The web control code is as follow:
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Text
Imports System.Web
Imports System.Web.UI
<DefaultProperty("Text"), ToolboxData("<{0}:TodayAtZulu runat=""server"" id=""TodayAtZulu""></{0}:TodayAtZulu>")> _
<Description("Get text of Today at Universal (Zulu) time.")> _
Public Class TodayAtZulu
Inherits System.Web.UI.Control
<Category("Value")> _
Public ReadOnly Property Text() As String
Get
Return Microsoft.SharePoint.Utilities.SPUtility.FormatDate(Microsoft.SharePoint.SPContext.Current.Web, System.DateTime.Now.ToUniversalTime, Microsoft.SharePoint.Utilities.SPDateFormat.ISO8601)
End Get
End Property
End Class
After deploying the control on the server, adding it to the form and using the control text as a parameter for filtering, all announcements result turn back correctly.
My question is: Is there a more elegant way?