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

MasterPage/PageLayout format DateTimeField

Posted by PANVEGA on March 16, 2009

When you are creating a SharePoint MasterPage or a Page Layout and you what to have a specific datetime format like dd.MM.yyyy  it’s not possible using just the publishing date field of SharePoint. However you can also create a new aspx page with a cs codebehind class and formating the date field, but it is much more offer to achieve this goal (developement, deployment etc.). See the following links below.

Current Situation:

I created a PageLayout with a Custom Content Type DateTime called MyDate field. The field is shown only with this format dd\MM\yyyy. I needed this format dd.MM.yy. Out of the box, you cannot format the date field.  The default date asp code behind look like this:

<SharePointWebControls:DateTimeField FieldName=”MyDate” runat=”server” id=”DateTimeField2″ CssClass=”datetimefield” >

Here is the way how to solve this issue in a few steps without VisualStudio:

Add a new calculated field to the content type that you are using on the page layout with the following formula:


Caution!!! If you have a updated SharePoint Version you have to replace “,”  with “;”  like =TEXT(DATEFIELD; “DATEFORMAT”)

Otherwise you receive an error message like this: The formula contains a syntax error or is not supported

In the date format you can put “d.MM.yy” or “dd-MM-yyyy” etc.

On your page layout replace the code above with the following:

<!–Edit Mode–>
<PublishingWebControls:editmodepanel runat=server id=”EditModePanel”>
<SharePointWebControls:datetimefield ID=”DateTimeField” FieldName=”MyDate” runat=”server”>
<!–Published Mode–>
<PublishingWebControls:editmodepanel runat=server id=”EditModePanel2″ PageDisplayMode=”Display”>
<SharePointWebControls:calculatedfield ID=”CalculatedField” FieldName=”PublishedDate” runat=”server” CssClass=”datetimefield”>

I created a new calculated column PublishedDate and added the formula like: =TEXT(“MyDate”,”dd.MM.yy”)

This will show on edit mode the MyDate field and on display mode the calculated PublishedDate  field.

You can use this trick on any list to show on your views different date formats.

Note: Edit your PageLayout first before you create any instances. Otherwise you could receive an error message.

More Stuff:


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: