Casey Crookston
Casey Crookston

Reputation: 13955

C# Data type for Birthdate

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.)

Upvotes: 5

Views: 14329

Answers (3)

Vivekanand Shigihalli
Vivekanand Shigihalli

Reputation: 41

Update: DateOnly (and TimeOnly) types (Structures) have been added to .NET 6.

See: How to use the DateOnly and TimeOnly structures.

Upvotes: 4

lem2802
lem2802

Reputation: 1162

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

Upvotes: 1

GregoryHouseMD
GregoryHouseMD

Reputation: 2378

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

Upvotes: 4

Related Questions