Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm editing the itemstyle.xsl to produce my own styling for a Content Query Web Part (CQWP) as follows: (NB - 2 laternative lines of code are shown as (A) and (B)

<xsl:template name="MyNewStyle" match="Row[@Style='MyNewStyle']" mode="itemstyle">
<div class="SipAddress">
  <xsl:value-of select="@SipAddress" />
</div>
<div class="LinkToolTip">
  <xsl:value-of select="@LinkToolTip" />
</div>
<div class="OpenInNewWindow">
  <xsl:value-of select="@OpenInNewWindow" />
</div>
<div class="OnClickForWebRendering">
  <xsl:value-of select="@OnClickForWebRendering" />
</div>
   <div>
   <table width="100%" >
   <tr>
      <td width="45%" ><xsl:value-of select="@Title" /></td>
       <td width="33%"><xsl:value-of select="@Location" /></td>
       (A) <td width="32%"><xsl:value-of select="@EventDate"/></td>
       (B) <td width="32%"><xsl:value-of select="msxsl:format-date(@EventDate, 'dd/mm/yyyy h:mm')"/></td>

   </tr>
  </table>         
  </div>

Using line (A) works in that all the data is all pulled through (I have also edited the CommonViewField in the webpart)

However the date appears in this format: 2011-04-21 10:00:00

So after a bit of googling I came across this: and replaced (A) with (B)

The date field disappeared... (sigh)

What do I need to do to make the date appear in the correct format?

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

After looking for ages for the answer to this I stumbled on it minutes after posting this question...

Anyway, the answer is here: http://blogs.msdn.com/b/joshuag/archive/2009/03/25/custom-date-formats-in-sharepoint-xsl.aspx

Summary:

  1. Reference the ddwrt namespace at the top of the itemstyle.xls xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"

  2. Now you can use the FormatDate function anywhere you like:

    <xsl:template name="Default" match="*" mode="itemstyle">
    <xsl:value-of select="ddwrt:FormatDate(@ArticleStartDate, 2057, 3)"/>
    </xsl:template>

share|improve this answer
    
Nice tip! Sometimes just writing out the problem is the way to a solution. –  Marc D Anderson Mar 30 '11 at 15:20
    
Great Post! But Im having hard time implementing on my portal using XsltListViewWebPart <xsl:apply-templates select="." mode="PrintFieldWithECB"> <xsl:with-param name="thisNode" select="$thisNode"/> </xsl:apply-templates> where $thisNode = Responded_x0020_On DateTime Type I tried doing the 2 sample but none of them seems to work. <xsl:value-of select="ddwrt:FormatDate(string(@Responded_x0020_On , 2057, 3)" /> <xsl:value-of select="ddwrt:FormatDate(@Responded_x0020_On , 2057, 3)"/> Any idea? Thanks. –  R2C3 Apr 26 '12 at 11:37
add comment

I found this as the easiest way to limit the date field.

 < xsl:variable name="cDate" select="@cDate"></xsl:variable>

 < xsl:value-of disable-output-escaping="yes" select="substring-before($cDate,' ')"></xsl:value-of>
share|improve this answer
    
Anonymous user notes that it works if you only want to display date and not the time. –  SPDoctor May 9 '13 at 21:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.