PANVEGA’s Blog

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.

http://sharepointers.blogspot.com/2008/09/publishing-page-layout-datetimefield.html

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

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” >
</SharePointWebControls: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:

=TEXT(DATEFIELD,”DATEFORMAT”)

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”>
</SharePointWebControls:DateTimeField>
</PublishingWebControls:EditModePanel>
<!–Published Mode–>
<PublishingWebControls:editmodepanel runat=server id=”EditModePanel2″ PageDisplayMode=”Display”>
<SharePointWebControls:calculatedfield ID=”CalculatedField” FieldName=”PublishedDate” runat=”server” CssClass=”datetimefield”>
</SharePointWebControls:CalculatedField>
</PublishingWebControls:EditModePanel>

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:

http://blog.ray1.net/2008/04/sharepoint-calculated-fields-use-excel.html

http://pathtosharepoint.wordpress.com/2008/08/14/calculated-columns-the-useless-today-trick

http://office.microsoft.com/en-us/help/HA101215881033.aspx

http://office.microsoft.com/en-us/sharepointtechnology/CH100650061033.aspx

http://blogs.msdn.com/sharepointdesigner/archive/2008/02/25/filtering-and-formatting-with-date-values.aspx

http://www.gothamweb.com/support/manual/wsshelp/html/EgForm.htm

Advertisements

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: