Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am working with my page layout and I have the following tag ...

<SharePointWebControls:DateTimeField FieldName="Article Date" runat="server" id="DateTimeField1" />

The only problem I have is I want the user to not only pick the date, but the time as well nd I have no idea how to set that property.

Thanks

Mike

share|improve this question
add comment

2 Answers 2

up vote 0 down vote accepted

In order to allow select Date and Time in DateTimeField control, specify for Date and Time field the Date & Time format

enter image description here

In your case for field Article Date format should be changed to Date & Time


DateOnly and TimeOnly properties of DateTimeField control

First of all, DateOnly and TimeOnly properties of DateTimeField control is not about specifying format of stored field values, but only indicates whether the control displays time values and(or) date values

Actually, specifying DateOnly and TimeOnly properties explicitly cause this error: System.NullReferenceException: Object reference not set to an instance of an object. at SharePoint.ControlExtender.WebControls.DateTimeField.set_DateOnly(Boolean value) at T_DateTimeField_DateOnly_11.SetProperty(Object , Object ) at System.Web.Util.FastPropertyAccessor.SetProperty(Object target, String propName, Object val, Boolean inDesigner) at System.Web.UI.PropertyMapper.SetMappedPropertyValue(Object obj, String mappedName, Object value, Boolean inDesigner) at System.Web.UI.ControlBuilder.SetSimpleProperty(SimplePropertyEntry entry, Object obj)

Article Date field is OOTB page field and declared like this (source):

<Field ID="{71316CEA-40A0-49f3-8659-F0CEFDBDBD4F}" 
       Name="ArticleStartDate" 
       StaticName="ArticleStartDate" 
       SourceID="http://schemas.microsoft.com/sharepoint/v3" 
       Group="$Resources:cmscore,group_publishingcolumns;" 
       DisplayName="$Resources:cmscore,column_articlestartdate_displayname;" 
       Type="DateTime" 
       Format="DateOnly" 
       Required="FALSE" 
       Sealed="TRUE" 
       StorageTZ="UTC">
</Field>

So, OOTB Article Date field is supported to store Dates only.

It is not recommended to change OOBT fields, the following solution demonstrates how to display Article Date with Date & Time format

How to display Article Date using Date & Time format

  1. Create custom Article Date field of Date & Time type and with Date & Time format
  2. Add this field to Content Type associated with Page Layout
  3. Add control declaration to page layout: <SharePointWebControls:DateTimeField FieldName="Custom Article Date and Time" runat="server" />
share|improve this answer
    
Ok, that column ('Article Date') is one of the publishing columns so it is out of the box and not editable. But in checking it says 'The type of information in this column is: Date and Time' So ... why is it not showing the time as well? –  mdumka May 3 '13 at 15:22
    
OK so then I tried changing the SharePointWebControls:DateTimeField to SharePointWebControls:DateTimeControl for Date and Time and got this error ... Type 'Microsoft.SharePoint.WebControls.DateTimeControl' does not have a public property named 'FieldName'. I am lost –  mdumka May 3 '13 at 15:28
    
The answer has been updated, basically, the recommendation is to create custom Article Date field with Date & Time format –  Vadim Gremyachev May 5 '13 at 11:51
    
Thanks Vadim, I was hoping it did not have to do that but with your great explanation I now know this is the right way to proceed. Thanks so much - Mike –  mdumka May 5 '13 at 16:06
add comment

Not certain but you could try setting DateOnly="false".

share|improve this answer
    
Tried that, but then my pages started throwing errors. –  mdumka May 1 '13 at 1:36
    
DateOnly is one of the most hideous properties. It will almost always throw errors in display mode –  Robert Lindgren May 3 '13 at 5:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.