Saturday, January 18, 2014

SharePoint 2013 CQWP ItemStyle.xsl - Match today's date

Following code demonstrate how we can match "Modified" date of an announcement and output if date is today rather than show date. 

List of LCID: http://msdn.microsoft.com/en-us/goglobal/bb964664.aspx
For list of LCID and Format also thanks goes to this blog:  http://blogs.msdn.com/b/joshuag/archive/2009/03/25/custom-date-formats-in-sharepoint-xsl.aspx


<xsl:variable name="AnnModifiedDate" select="ddwrt:FormatDate(@Modified,3081,1)"/>
<xsl:variable name="TodayDate" select="ddwrt:FormatDate(ddwrt:Today(),3081,1)"/>
<span class="anndate">
  <xsl:choose>
    <xsl:when test="$AnnModifiedDate = $TodayDate">
      <xsl:text>
        Today
      </xsl:text>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$AnnModifiedDate"/>
    </xsl:otherwise>
  </xsl:choose>
</span>



Explanation:
This code converts the Modified and Current date to Australian date format (d/m/yyyy) and does the match.
If matched outputs "Today" else the date.

No comments: