Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - XPath Reference

ms:format-date Function

Converts standard XSD date formats to characters suitable for output.

string ms:format-date(string datetime, string format [,locale])

Parameters

string datetime
contains a date-related value in XSD format. For nonstring arguments, this function behaves as if a string() function were applied. If the argument is not a date, the output is an empty string. If it is a valid XSD date and some fields are emtpy, this function attempts to fill unspecified fields.
string format
Contains a format string, according to Win32 API GetDateFormat functions.
locale [optional]
Defines the locale to format the data for (for example, "EN_us").

Remarks

The following lists the format characters for ms:format-date().

Character(s) Description
M Months as 1-12
MM Months as 01-12
MMM Months as Jan-Dec
MMMM Months as January-December
d Days as 1-31
dd Days as 01-31
ddd Days as Sun-Sat
dddd Days as Sunday-Saturday
y Years as 0-99
yy Years as 00-99
yyyy Years as 1900-9999
gg Period/era (ignored if there isn't one)

Note that this format does not allow time zones; does not allow the inclusion of abitrary text into the formatted string; does not allow centuries; does not allow suffixes like May 2nd or April 1st.

Example

XML Document (Sample.xml)

<?xml version='1.0'?>
<XMLSamples xml:space="preserve"
         xmlns:dt="urn:schemas-microsoft-com:datatypes">
  <FileDetails>
   <Author>Robert Brown</Author>
   <Date dt:dt="datetime">2000-02-16T15:56:00</Date>
  </FileDetails>
</XMLSamples>

XSLT Style Sheet (Sample.xsl)

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:ms="urn:schemas-microsoft-com:xslt"
      xmlns:dt="urn:schemas-microsoft-com:datatypes">
  <xsl:template match="/">
  <HTML>
  <HEAD>
  </HEAD>
  <BODY> 
   <xsl:for-each select="XMLSamples/FileDetails/Date">
      <DIV>
          Date Unedited:
          <xsl:value-of select="."/>
      </DIV>
      <DIV>
          Date Edited:
          <xsl:value-of select="ms:format-date(., 'MMM dd, yyyy')"/>
      </DIV>
   </xsl:for-each>
  </BODY> 
  </HTML>
</xsl:template>
</xsl:stylesheet>

Output

The output HTML page shows the following entries:

Date Unedited: 2000-02-16T15:56:00
Date Edited: Feb 16, 2000

See Also

Data Types in Schemas | XML Schema Reference (XSD) | XML Data Types Reference