ddwrt FormatDate and FormatDateTime

As evidenced in the latest blogs, I’ve been spending a lot of time aggregating my content types into customized Content Query Web Parts (CWQP).  Soon, I’m going to need to branch out to other web parts.

Something I needed to research today which took longer than it should have:  how do you format the datetime elements when you use the ddwrt namespace?

Here’s a resource for customizing the CQWP: http://www.microsoft.com/belux/msdn/nl/community/columns/stevenvandecraen/contentquerywebpart.mspx
This page helped: http://msdn.microsoft.com/en-us/library/aa505323.aspx#officesharepointddwrt_formatdate
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
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

I also learned that "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> 

About these ads

6 thoughts on “ddwrt FormatDate and FormatDateTime

  1. Hi,
    I have found a mistake in your post:

    the examples below should be reversed

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

    actually

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

    Best wishes,

    Slava G
    Wylde Solutions

  2. I keep referring to this post. As I am in the UK I tend to use an
    lcid of “2057″ otherwise I don’t get my dd Month name,

  3. Hi,

    I am currently filtering for current month birthdays:

    using this:
    [substring-after(@ows_BirthMonthNumber,'#')=number(ddwrt:FormatDateTime(string(ddwrt:Today()),1033,'MM'))]

    This brings back the entire month. How can I just bring back the current 2 weeks from todays date for bdays?

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