Content Query Web Part with formatted date in Sharepoint 2010

27. March 2011 21:56 by Mahmoud Farhat in   //  Tags:   //   Comments (0)
In this post I am going to show step by step how to format the datetime in your own item style in sharepoint 2010

1-     Open your top-level site in Sharepoint Designer, click “All Files – Style Library – XSL Style Sheets – ItemStyle.xsl” and click Edit, I prefer to get a  backup from this file before do any changes.

2-     
In the top of the file, add this line so we can format the date further down the road: 
xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
3-     Add this at the bottom of the variables section:
<xsl:variable name="Created"> 
<xsl:value-of select="ddwrt:FormatDateTime(string(@Created) ,1033 ,'dd/MM/yyyy')" />
</xsl:variable>
The following lists of the language packs that are available for Office SharePoint Server 2010.
 
Arabic     Saudi Arabia (Hijri)    1025
English    United States               1033
 
 4-      Then you can use the variable
	<strong><xsl:value-of select="$Created"/></strong>
 
Full Sample:
<xsl:template name="Test_template" match="Row[@Style='Test_template']" mode="itemstyle">
     <xsl:variable name="CurrentDate">
         <xsl:value-of select="ddwrt:FormatDateTime(string(@Date) ,1025 ,'yyyy/MM/dd')" />
     </xsl:variable>
     <div style="width:400px;  height:100px;text-align:right;">
                     <div style="text-align:right;">
             <xsl:value-of select="$CurrentDate"/>
         </div>
     </div>
 </xsl:template>