I have already seen this.
I am going to get only Date from a DateTime variable and in this way I used this code:
DateTime Start = GetaDateTime();
String Day = Start.ToString("yyyy/MM/dd");
DateTime d = Convert.ToDateTime(Day);
But when I use d.Date
it gives me '2014-08-23 12:00 AM'
Actually I should not get 12:00AM
any more????
Actually I should not get 12:00AM any more????
Why not? A DateTime
has no notion of whether it's meant to be a date or a date and time, or any sort of string formatting. It's just a point in time (and not even quite that, given the odd Kind
part of it).
Note that a simpler way of getting a DateTime
which is the same as another but at midnight is just to use Date
to start with:
DateTime start = Foo();
DateTime date = start.Date;
No need for formatting and then parsing.
There's no .NET type representing just a date. For that, you'll want something like my Noda Time project, which has a rather richer set of date/time types to play with.
See more on this question at Stackoverflow