Tags: Properties

Episerver DateTime property without the Time!

Episerver has several built-in property types you may add to your content types, including DateTime that displays a date and time picker. Sometimes you do not want the time, only the Date!

The date and time picker looks like this:

Episerver DateTime-picker

We can fix that! Create a new editor descriptor like this:

[EditorDescriptorRegistration(TargetType = typeof(DateTime?), UIHint = "DateOnly")]
public class DateEditorDescriptor : EditorDescriptor
{
    public override void ModifyMetadata(ExtendedMetadata metadata, IEnumerable<Attribute> attributes)
    {
        base.ModifyMetadata(metadata, attributes);
        ClientEditingClass = "dijit/form/DateTextBox";
    }
}

Add the UIHint to your property definition, like this:

[UIHint("DateOnly")]
public virtual DateTime? StartDate { get; set; }

The date and time picker are now replaced with a date picker!

Episerver Date-picker

Found this post helpful? Help keep this blog ad-free by buying me a coffee! ☕