Sunday, November 13, 2011

Format DateTime in SharePoint 2010 based on XSLT 1.0

If you were bored with the date time formatted showed in the list by SharePoint and you think it should be changed to how it's easy to view it. The difficulties come from a lot of problems especially XSLT in SharePoint 2010, it was never upgraded from SharePoint 2002, still using version 1.0 until now. That's the bad thing I had when I was working on SharePoint.

Of course, there are many options for you developing on SharePoint product, I mean you can use ContentQuery Web Part to correct the date time format like FaceBook or Google Plus:

However, to do that, now you just follow up this instruction to customize your xslt and see how it shows on the page.

Click here to download the library.

1) Copy the content of file after downloaded, paste it into the file named "thread.xsl" in folder 14/Template/Layouts/Xsl

2) Go to the line for template called "StatusBar" (<xsl:template name="StatusBar">) and remove all the code for Modified date time. Or replace by:

<xsl:call-template name="Bamboo_FormatDateTime">
    <xsl:with-param name="theDate" select="$thisNode/@Modified."/>
    <xsl:with-param name="theDateFormat" select="$thisNode/@Modified"/>
</xsl:call-template>

3) Save and reset IIS

Note: 
- You can put the code anywhere if you want to show the time stamp more friendly.
- Just StatusBar column has defined "Modified." field in the schema, it's original value of Modified column. So, if you do not find out the value of "Modified." that means, in the schema file, the field did not create a reference to original value Modified.
- You also don't care about the LCID of site or user locate, because the value of "Modified." always return the value in 1033 regional and the format function based on this column to show friendly.

1 comment:

Sudheer Gangumolu said...

Nice Article,

You can find user friendly date time format programmatically http://sharepointsolutions-sudheer.blogspot.in/2014/12/user-friendly-time-in-sharepoint.html