Skip to content

Compensating for All Day Event Error in SharePoint 2010 XSL for Content Query Web Part Item Styles

by on March 22, 2012

When SharePoint sets an event to all day, for some reason the return date defaults to the day BEFORE the event (ie. if it is the 23rd, you get the 22nd).

This is highly irritating, and confusing to the end user.

After further research , it appears that unlike all other event date revtreival, SP returns the UTC date for all day events, not the localized date (GMT adjusted). Big oversight on the part of MS! This really needs to be fixed!

All event dates are apparently stored in GMT and extrapolated on retrieval.

A quick fix for a Custom Item Style is to pull in the “All Day Event” field, and if it is true (which in programming will mean it equals the number 1), add that to the day of the event.

Unfortunately, if you are looking for a more pleasing date display, it gets a bit more complicated.

Desired Date Format

Tuesday, January 1, 2013

The XSL Code

I have split full day (Tuesday), day, month, and year into variables for easy management and then concatenated the final output I want using the calculated date. Enter this into any new or custom item style. It does not account for leap years.

<xsl:variable name="fullday" select="ddwrt:FormatDateTime(string((@EventDate)),1033,’dddd’)" />
                <xsl:variable name="day" select="ddwrt:FormatDateTime(string((@EventDate)),1033,’dd’)" />  
                <xsl:variable name="month" select="ddwrt:FormatDateTime(string((@EventDate)),1033,’MMMM’)" />
                <xsl:variable name="year" select="ddwrt:FormatDateTime(string((@EventDate)),1033,’yyyy’)" />
                <xsl:variable name="calculatedDay" select="$day+@AllDayEvent"/>
                <xsl:variable name="correctedFullDay">
                  <xsl:if test="@AllDayEvent = ‘1’">
                    <xsl:if test="$fullday = ‘Monday’">
                     Tuesday
                     </xsl:if>
                     <xsl:if test="$fullday = ‘Tuesday’">
                     Wednesday
                     </xsl:if>
                    <xsl:if test="$fullday = ‘Wednesday’">
                     Thursday
                     </xsl:if>
                     <xsl:if test="$fullday = ‘Thursday’">
                     Friday
                     </xsl:if>
                     <xsl:if test="$fullday = ‘Friday’">
                     Saturday
                     </xsl:if>
                     <xsl:if test="$fullday = ‘Saturday’">
                     Sunday
                     </xsl:if>
                     <xsl:if test="$fullday = ‘Sunday’">
                     Monday
                     </xsl:if>
                   </xsl:if>
                   <xsl:if test="@AllDayEvent = ‘0’">
                       <xsl:value-of select="$fullday"/>
                   </xsl:if>
                </xsl:variable>
                <xsl:variable name="correctedFullDate">
                    <xsl:choose>
                        <xsl:when test="@AllDayEvent = ‘1’">
                            <xsl:choose>
                                <xsl:when test="$month = ‘January’ and $calculatedDay = ’32’">
                                    <xsl:value-of select="concat($correctedFullDay, ‘, ‘, ‘February 1, ‘, $year)" />
                                </xsl:when>
                                <xsl:when test="$month = ‘February’ and $calculatedDay = ’30’">
                                    <xsl:value-of select="concat($correctedFullDay, ‘, ‘, ‘March 1, ‘, $year)" />
                                </xsl:when>
                                <xsl:when test="$month = ‘March’ and $calculatedDay = ’32’">
                                    <xsl:value-of select="concat($correctedFullDay, ‘, ‘, ‘April 1, ‘, $year)" />
                                </xsl:when>
                                <xsl:when test="$month = ‘April’ and $calculatedDay = ’31’">
                                    <xsl:value-of select="concat($correctedFullDay, ‘, ‘, ‘May 1, ‘, $year)" />
                                </xsl:when>
                                <xsl:when test="$month = ‘May’ and $calculatedDay = ’32’">
                                    <xsl:value-of select="concat($correctedFullDay, ‘, ‘, ‘June 1, ‘, $year)" />
                                </xsl:when>
                                <xsl:when test="$month = ‘June’ and $calculatedDay = ’31’">
                                    <xsl:value-of select="concat($correctedFullDay, ‘, ‘, ‘July 1, ‘, $year)" />
                                </xsl:when>
                                <xsl:when test="$month = ‘July’ and $calculatedDay = ’32’">
                                    <xsl:value-of select="concat($correctedFullDay, ‘, ‘, ‘August 1, ‘, $year)" />
                                </xsl:when>
                                <xsl:when test="$month = ‘August’ and $calculatedDay = ’32’">
                                    <xsl:value-of select="concat($correctedFullDay, ‘, ‘, ‘September 1, ‘, $year)" />
                                </xsl:when>
                                <xsl:when test="$month = ‘September’ and $calculatedDay = ’31’">
                                    <xsl:value-of select="concat($correctedFullDay, ‘, ‘, ‘October 1, ‘, $year)" />
                                </xsl:when>
                                <xsl:when test="$month = ‘October’ and $calculatedDay = ’32’">
                                    <xsl:value-of select="concat($correctedFullDay, ‘, ‘, ‘November 1, ‘, $year)" />
                                </xsl:when>
                                <xsl:when test="$month = ‘November’ and $calculatedDay = ’31’">
                                    <xsl:value-of select="concat($correctedFullDay, ‘, ‘, ‘December 1, ‘, $year)" />
                                </xsl:when>
                                <xsl:when test="$month = ‘December’ and $calculatedDay = ’32’">
                                    <xsl:value-of select="concat($correctedFullDay, ‘, ‘, ‘January 1, ‘, $year+1)" />
                                </xsl:when>

                                <xsl:otherwise>
                                    <xsl:value-of select="concat($correctedFullDay, ‘, ‘, $month, ‘ ‘ , $calculatedDay, ‘, ‘,$year)" />
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:value-of select="concat($correctedFullDay, ‘, ‘, $month, ‘ ‘ , $calculatedDay,’, ‘, $year)" />
                        </xsl:otherwise>
                    </xsl:choose>
                </xsl:variable>
                 <p class="calendardate"><xsl:value-of select="$correctedFullDate"/></p>

NOTE: You must include the ddwrt reference in the itemstyle.xsl file for this to work: xmlns:ddwrt=http://schemas.microsoft.com/WebParts/v2/DataView/runtime

Item Style Settings

When using the item style on a Content Query Web Part (CQWP), you simply enter in “All Day Event” into the “AllDayEvent” Field, and “Start Date” into the “EventDate” field.

Updated: 4/26/2012

Advertisements
3 Comments
  1. I ran across the same issue. root cause seems to be internally all day events are converted to GMT so for us that is 5 hours before midnight, which moves it to the prior day.

    But it looks like using this will end up with the wrong value if the all day event is on the first of the month.

  2. Jon permalink

    Had the same issue. I just instructed users to change from all day event to 12am to 11pm and the date displayed correctly.

  3. I just created a calculated date field to adjust for the GMT differential to use for filters. For example:
    Formula:
    =[Start Time]+TIME(5,0,0)

    This is for EST where my office is located. The only problem is that this does not adjust for DST. So twice a year, you have to go in and change the number in the formula up or down by 1. If you don’t have DST where you are located, you can just make the field and not have to worry about adjusting it.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: