PANVEGA’s Blog

DotNet Development, SharePoint Customizing, Silverlight, MS Infrastructure and other tips and tricks

ddwrt:FormatDate with different FormatFlags

Posted by PANVEGA on December 8, 2008

I needed to use the ddwrt functions in my content query web part. Using the FormatFlags you can easily transform the format you wish.

Add the following namespace attribute to the root xsl:stylesheet element

xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"

This provided more examples of the FormatDateTime formatting codes (like YYYYMMDDThh:mm):

http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

Here’s a list of languages with their LCID:

http://support.microsoft.com/default.aspx?id=221435

Language packs for Office SharePoint Server 2007 are not bundled into multilingual installation packages. You must install a specific language pack for each language that you want to support. Also, language packs must be installed on each of your front-end Web servers to ensure that each Web server can render content in the specified language.

The following table lists the language packs that are available for Office SharePoint Server 2007.

German Germany 1031
English United States 1033
Japanese Japan 1041

The FormatDate function date formates are expressed with an integer, here are a couple of examples:
ddwrt:FormatDate(string(@EventDate), 1033, 5) => MM/DD/YYYY
ddwrt:FormatDate(string(@EventDate), 1033, 1) => MM/DD/YYYY HH:MM AM/PM

dateflags

Note that in the FormatDate function I used 2 hard coded values – 3081 which is the LCID for German (so the date will be formatted to Germany date format) and 5 or 1 are the different FormatFlags which specifies the what do I want to display – date, time, date and time ect.

Sharepoint works with dates in the ISO8601 format: yyyy-mm-ddThh:mm:ssZ so when I delve into CAML I can write stuff like this:

<Query>
<Where>
<Gt>
<FieldRef Name=”EventDate” />
<Value Type=”DateTime”>2005-5-27T00:00:00Z</Value>
</Gt>
</Where>
</Query>

More links:

http://msdn.microsoft.com/en-us/library/aa505323.aspx#officesharepointddwrt_formatdate

Advertisements

4 Responses to “ddwrt:FormatDate with different FormatFlags”

  1. […] with Date formats again in SharePoint, and came across a  good tip from Panvega worth a shout – Using ddwrt:FormatDate in the CQWP. I needed to take the Publishing date for a page and reformat it (I don’t need […]

  2. Jordan J said

    Based on the chart your example is incorrect.

    ddwrt:FormatDate(string(@EventDate), 1033, 5) => MM/DD/YYYY
    ddwrt:FormatDate(string(@EventDate), 1033, 1) => MM/DD/YYYY HH:MM AM/PM

    Change it to

    ddwrt:FormatDate(string(@EventDate), 1033, 1) => MM/DD/YYYY
    ddwrt:FormatDate(string(@EventDate), 1033, 5) => MM/DD/YYYY HH:MM AM/PM

    Thanks for posting this chart.

  3. PANVEGA said

    Thanks for that. All possible formats you are going to find in the LCID List above.

  4. Thank you! I am still learning working with Sharepoint.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: