0

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????

Community
  • 1
  • 1
Kam Par
  • 81
  • 1
  • 2
  • 8
  • 3
    `Date` returns a `DateTime`. It has 12:00AM because that is the default for the Time portion. There is no built-in `Date` data type in c#. – gunr2171 Aug 26 '14 at 19:57

1 Answers1

7

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.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194