Reputation: 1494
I want do have my DateTime get displayed without the time.
So I use
item.AD_Date.Date
to cut off the time.
In the Model ( I use MVC) AD_Date is set up like this:
public System.DateTime AD_Date { get; set; }
But I get my date like this:
01.03.2013 00:00:00
What did I do wrong?
Upvotes: 0
Views: 137
Reputation: 1494
If someone is facing the same problem, here is my formatting :
@String.Format("{0:yyyy-MM-dd}", item.AD_Date)
Upvotes: 0
Reputation: 1500525
The Date
property just returns a DateTime
with the same date, but at midnight. There's no difference between "a DateTime
at midnight" and "a DateTime
just representing a date" (unfortunately).
You need to change how your DateTime
is formatted to only show the date - either by annotating the model or by changing the view.
(Alternatively, use my Noda Time library which has different types for the different kinds of data you want to represent. I haven't tried using it with MVC, but at least for the formatting side it should work okay...)
Upvotes: 1