The Case of the Different Dates

I ran into an issue in an MVC application where I had two dates in a table. One was being displayed as just a date, and the other included the time component as well. I just wanted the date. The difference was that the property in the model for the time-less date had a DataType attribute and the other date didn’t:

Right:

       [DataType(DataType.Date)]
       [DisplayName("Enter Date")]
       public DateTime EnterDate { get; set; }

Wrong:

       [DisplayName("Work Date")]
       public DateTime WorkDate { get; set; }

Adding the attribute fixed the issue.

Advertisements
  1. Leave a comment

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: