Tuesday, July 26, 2011

XSL Date using ddwrt Namespace

The following comes from: http://msdn.microsoft.com/en-us/library/dd583143(v=office.11).aspx

XSL Date using ddwrt Namespace... NOTE: Ensure the xsl stylesheet includes a reference to ddwrt ... Eg:

<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal" xmlns:o="urn:schemas-microsoft-com:office:office">

Functions:

public string FormatDate(string szDate, long lcid, long formatFlag);
<xsl:value-of select="ddwrt:FormatDateTime(ddwrt:TodayIso(),2057,'dddd MMMM dd yyyy')" />

public string TodayIso();
<xsl:value-of select="ddwrt:TodayIso()"/>

public string Today();
<xsl:value-of select="ddwrt:Today()"/>

  • Date only as M/d/yyyy. Example: "08/17/2000".
  • Date only as dddd, MM dd, yyyy. Example: "Thursday, August 17, 2000".
  • Time only as h:mm. Example: "16:32".
  • DateTime as M/d/yyyy h:mm. Example: "08/17/2000 16:32".
  • DateTime as dddd, MM dd, yyyy h:mm. Example: "Thursday, August 17, 2000 16:32".
  • Time only as h:mm:ss. Example: "16:32:32".
  • DateTime as M/d/yyyy h:mm:ss. Example: "08/17/2000 16:32:32".
  • DateTime as dddd, MMMM dd, yyyy h:mm:ss. Example: "Thursday, August 17, 2000 16:32:32".

    3 comments:

    1. How to change Timestamp to 12 hour format i.e 5:23 am or 12 :45 pm?

      ReplyDelete
    2. Hi - see example below:value-of
      ddwrt:FormatDateTime(string(@End_x0020_Time), 1033, 'yyy-MM-dd hh:mm tt'

      ReplyDelete
    3. Hi i need format like monday 27th febrarury 2012. i used
      i m getting output like monday 27 febrarury 2012.I need to addsuffix like 27th,9th,1st .. what shall i do?

      ReplyDelete