Question: I have two separate fields on the page: one for date and one for time.

This is the model:

```
[Required]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:hh:mm tt}")]
public DateTime? StartTime { get; set; }

[Required]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
public DateTime Date { get; set; }

```

This is the view:

```
@Html.TextBoxFor(m => m.Date, "{0:MM/dd/yyyy}", new { type = "text" })
@Html.TextBoxFor(m => m.StartTime, "{0:hh:mm tt}", new { type = "text", id = "timeStart" })

```

The javascript unobtrusive validation works fine with the `Date` field however when i enter "11:00 PM" or "11:00 pm" in `StartTime` the validation shows 

> 
> "The field StartTime must be a date"
> 
> 
> 

Server side validation works fine with `"0:hh:mm tt"` it's only the javascript that has a problem. For now i just disabled javascript validation but would like eventually to have it on this page

Can this be done for "time" field?

Answer: 
Add `DataType.Time` attribute to your time field and use `EditorFor`s to remove format duplication:

*Model*

```
    [Required]
    [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:hh:mm tt}")]
    [DataType(DataType.Time)]
    public DateTime? StartTime { get; set; }

    [Required]
    [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
    public DateTime Date { get; set; }

```

*View*

```
    @Html.EditorFor(m => m.Date, new { type = "text" })
    @Html.EditorFor(m => m.StartTime, new { type = "text", id = "timeStart" })

```
In your view model try this

```
    [Display(Name = "Start Time")]
    [Time]
    [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:hh:mm tt}")]
    public DateTime Time { get; set; }

```

and have the attribute class

```
public class TimeAttribute : ValidationAttribute, IClientValidatable
{
    public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata,
                                                                        ControllerContext context)
    {
        yield return new ModelClientValidationRule
        {
            ErrorMessage = ErrorMessage,
            ValidationType = "time"
        };
    }

    public override bool IsValid(object value)
    {
        DateTime time;
        if (value == null || !DateTime.TryParse(value.ToString(), out time))
            return false;

        return true;
    }
}

```

EDIT: I'm also aware that in some cases you need to add some scripting to the client html such as that found in this answer [MVC3 unobtrusive validation group of inputs](https://stackoverflow.com/questions/5816313/mvc3-unobtrusive-validation-group-of-inputs/5817958#5817958) although I'm not exactly sure when its necessary. This answer should get you half way there. Unfortunately, I'm not sure this answer prevents the postback, but it does flag the model as invalid.