5

There is no Date type. If I want an object that is only a date with no time, like a birthdate, what type would I use?

I'm sure this question has been asked and answered already, but I'm not finding this exact question, only lots about date and datetime in general.

Thanks!

(Edit: I am not asking how to remove the date, or the time, from a DateTime. I was hoping that there might be a data type that stores ONLY date, and not a date and a time together. The answer, it seems, is No.)

Casey Crookston
  • 10,362
  • 17
  • 70
  • 150
  • Well, it's obvious that you only want the `date` part of a `datetime` so I suggest you use the [Date](https://msdn.microsoft.com/en-us/library/system.datetime.date.aspx) property of the [DateTime](https://msdn.microsoft.com/en-us/library/System.DateTime_properties(v=vs.110).aspx) struct. For more info, see this dupe link: [How to remove time portion of date in C# in DateTime object only?](http://stackoverflow.com/questions/6121271) – Bjørn-Roger Kringsjå Jul 08 '15 at 17:54

2 Answers2

3

There is no just Date type, use the DateTime data type and only set the date, the time will be all 0s.

GregoryHouseMD
  • 1,726
  • 1
  • 13
  • 34
  • 2
    @CaseyCrookston - you could make your own `Date` struct if you really want one. – Howard Renollet Jul 08 '15 at 17:39
  • 3
    you *could*, yes. and then you could write all of the infrastructure around `DateTime` and `DateTimeOffset`, and handle all the calendars and daylight savings, etc. but why would you, when someone's already done all that work? – John Gardner Jul 08 '15 at 18:24
1

There not is an only Date type... Use Date type, and set only the date, and to get only the date use ex: DateTime.Now.Date

lem2802
  • 1,112
  • 7
  • 18