If you are going to use ddwrt date formatting in your Data View Web Part, you must include the line:
xmlns:ddwrt=http://schemas.microsoft.com/WebParts/v2/DataView/runtime
... inside the <xsl:stylesheet ...> tag, like this:
<xsl:stylesheet
version="1.0" exclude-result-prefixes="xsl msxsl ddwrt"
xmlns:x="http://www.w3.org/2001/XMLSchema"
xmlns:dsp="http://schemas.microsoft.com/sharepoint/dsp"
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:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">
The 1033 LCID is used for US date formatting and the 2057 LCID is for UK date formatting. Where there's a hyphen in the Result column below, it means that the relevant ddwrt value produced no result for me.
DDWRT value | Result |
<xsl:value-of select="ddwrt:FormatDate(string(@StartDate),1033,1)" /> | 2/21/2016 |
<xsl:value-of select="ddwrt:FormatDate(string(@StartDate),1033,2)" /> | - |
<xsl:value-of select="ddwrt:FormatDate(string(@StartDate),1033,3)" /> | Sunday, February 21, 2016 |
<xsl:value-of select="ddwrt:FormatDate(string(@StartDate),1033,4)" /> | 1:00 PM |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,5)" /> | 2/21/2016 1:00 PM |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,6)" /> | 1:00 PM |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,7)" /> | Sunday, February 21, 2016 1:00 PM |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,8)" /> | - |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,9)" /> | 2/21/2016 |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,10)" /> | - |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,11)" /> | Sunday, February 21, 2016 |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,12)" /> | 1:00:00 PM |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,13)" /> | 2/21/2016 1:00:00 PM |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,14)" /> | 1:00 PM |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,15)" /> | Sunday, February 21, 2016 1:00:00 PM |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,16)" /> | - |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,17)" /> | 2/21/2016 |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,18)" /> | - |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,19)" /> | Sunday, February 21, 2016 |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,20)" /> | 1:00 PM |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,21)" /> | 2/21/2016 1:00 PM |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,22)" /> | 1:00 PM |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,23)" /> | Sunday, February 21, 2016 1:00 PM |
<xsl:value-of select="ddwrt:FormatDate(string(@StartDate),1033,25)" /> | 2/21/2016 |
<xsl:value-of select="ddwrt:FormatDate(string(@StartDate),1033,27)" /> | Sunday, February 21, 2016 |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,28)" /> | 1:00:00 PM |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,29)" /> | 2/21/2016 1:00:00 PM |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),1033,30)" /> | 1:00:00 PM |
DDWRT value | Result |
<xsl:value-of select="ddwrt:FormatDate(string(@StartDate),2057,1)" /> | 21/02/2016 |
<xsl:value-of select="ddwrt:FormatDate(string(@StartDate),2057,2)" /> | - |
<xsl:value-of select="ddwrt:FormatDate(string(@StartDate),2057,3)" /> | 21 February 2016 |
<xsl:value-of select="ddwrt:FormatDate(string(@StartDate),2057,4)" /> | 13:00 |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,5)" /> | 21/02/2016 13:00 |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,6)" /> | 13:00 |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,7)" /> | 21 February 2016 13:00 |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,8)" /> | - |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,9)" /> | 21/02/2016 |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,10)" /> | - |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,11)" /> | 21 February 2016 |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,12)" /> | 13:00:00 |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,13)" /> | 21/02/2016 13:00:00 |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,14)" /> | 13:00:00 |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,15)" /> | 21 February 2016 13:00:00 |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,16)" /> | - |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,17)" /> | 21/02/2016 |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,18)" /> | - |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,19)" /> | 21 February 2016 |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,20)" /> | 13:00 |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,21)" /> | 21/02/2016 13:00 |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,22)" /> | 13:00 |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,23)" /> | 21 February 2016 13:00 |
<xsl:value-of select="ddwrt:FormatDate(string(@StartDate),2057,25)" /> | 21/02/2016 |
<xsl:value-of select="ddwrt:FormatDate(string(@StartDate),2057,27)" /> | 21 February 2016 |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,28)" /> | 13:00:00 |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,29)" /> | 21/02/2016 13:00:00 |
<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,30)" /> | 13:00:00 |
If you're using the FormatDateTime specifier, it doesn't matter whether you define the LCID as 1033 or 2057.
DDWRT value | Result |
<xsl:value-of select="ddwrt:FormatDateTime(string(@EventDate),1033,'dd-MMM-yy')" /> | 21-Jan-15 |
<xsl:value-of select="ddwrt:FormatDateTime(string(@EventDate),1033,'dd/MM/yy')" /> | 21/01/15 |
<xsl:value-of select="ddwrt:FormatDateTime(string(@EventDate),1033,'dd/M/yy')" /> | 21/1/15 |
<xsl:value-of select="ddwrt:FormatDateTime(string(@EventDate),1033,'ddd, dd/M/yy')" /> | Sun, 21/1/15 |
<xsl:value-of select="ddwrt:FormatDateTime(string(@EventDate),1033,'dddd, dd/M/yy')" /> | Sunday, 21/1/15 |
The full list of specifiers is as follows:
Specifier | Result |
d | Day of the month, single digit 1-9, double digit 10 up |
dd | Day of the month, leading zero 1-9, double digit 10 up |
ddd | Abbreviated day of the week, ie, Wed |
dddd | Full name of the day of the week |
Specifier | Result |
M | The month, 1 to 12 |
MM | The month, 01 to 12 |
MMM | Abbreviated name of the month |
MMMM | Full name of the month |
Specifier | Result |
y | The year, from 0 to 99 |
yy | The year, from 00 to 99 |
yyy | The year with a minumum of three digits, ie 900 |
yyyy | The year as a four-digit number |
You can also add the following, if you want to display the time, as well:
Specifier | Result |
h | 12-hour clock, 1 to 12 |
hh | 12-hour clock, 01 to 12 |
H | 24 hour clock, 1 to 24 |
HH | 24 hour clock, 01 to 24 |
m | Minutes, 0 to 59 |
mm | Minutes, 00 to 59 |
s | Seconds, 0 to 59 |
ss | Seconds, 00 to 59 |
Use anything you like to separate the components ... a dash, a slash or wordpsaces and/or commas.
Hope this helps someone.
I think you forgot the minutes specifiers in the last table. I am using the following: yyyy-MM-dd hh:mm, 2017-07-24 09:20.
ReplyDeleteGood spot ... I've added those above ...
DeleteYou don't need to call string '<xsl:value-of select="ddwrt:FormatDate(string(@EventDate),2057,30)" />'.
ReplyDeleteThis is enough: '<xsl:value-of select="ddwrt:FormatDate(@EventDate,2057,30)" />'
Very apreciatted! It's help me
ReplyDelete