Ticket T435779
Visible to All Users

DateEdit - How to edit only hours in the time picker

created 9 years ago

I would like to offer a DateEdit with a Time Picker that only allows the user to select hours (i.e. 2:00 PM) and not allow minutes (i.e. 2:13 PM).  I am currently using this:

@Html.DevExpress().DateEdit(settings =>
    {
        settings.Name = "dateEdit4";
        settings.Properties.UseMaskBehavior = true;
        settings.Properties.EditFormat = EditFormat.Custom;
        settings.Properties.EditFormatString = "dd/MM/yyyy hh:mm tt";
        settings.Properties.TimeSectionProperties.Visible = true;
        settings.Properties.TimeSectionProperties.TimeEditProperties.EditFormat = EditFormat.Custom;
        settings.Properties.TimeSectionProperties.TimeEditProperties.EditFormatString = "hh:mm tt";
        settings.Date = DateTime.Now;
        settings.Width = Unit.Percentage(50);
    }).GetHtml()

Answers approved by DevExpress Support

created 9 years ago (modified 8 years ago)

Hello,

To accomplish this task and prevent the user from entering minutes, I suggest you hide the minute editor in the dropdown by setting the TimeSectionProperties.TimeEditProperties.EditFormatString property to "hh" and set a fixed minute number in EditFormatString as follows:

C#
@Html.DevExpress().DateEdit(settings => { settings.Name = "dateEdit4"; settings.Properties.UseMaskBehavior = true; settings.Properties.EditFormat = EditFormat.Custom; settings.Properties.EditFormatString = "dd/MM/yyyy hh:00 tt"; settings.Properties.TimeSectionProperties.Visible = true; settings.Properties.TimeSectionProperties.TimeEditProperties.EditFormat = EditFormat.Custom; settings.Properties.TimeSectionProperties.TimeEditProperties.EditFormatString = "hh"; settings.Date = DateTime.Now; settings.Width = Unit.Percentage(50); }).GetHtml()

Let us know if this approach meets your requirements.

    Show previous comments (3)
    DevExpress Support Team 8 years ago

      Hello Carlton,

      To my regret, it is not possible to accomplish this task using DateEdit's built-in features. As a possible workaround, you can implement separate editors for hours and minutes ("half hour") sections using two SpinEdit components and get their values to compose the final DateTime value.

        That will work.  Thanks.

        DevExpress Support Team 8 years ago

          You're welcome!

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.