Date object vs. DateTime object
12,244
The CLR classes (e.g. DateTime
, Int32
, etc.) contain the actual implementation. This is what you will see in Reflector.
Due to their heritage, C# and VB define certain aliases for commonly used data types. For example, int
in C# is an alias of Int32
. In VB, one such alias is Date
for DateTime
.
Here are lists of these aliases:
Comments
-
gh9 almost 2 years
I am currently looking at the msdn pages for the date and datetime object. I also have reflector opened up, and it looks like the date and datetime object just reference the Date structure. Why do we have two objects which reference the same structure? what is the differences between them?
-
MattDavey about 13 yearsAs of .NET 4, DateTimeOffset is the recommended way to represent date/time information. DateTime is essentially deprecated.
-
Andrew Hare about 13 years@MattDavey: [citation needed] :)
-
MattDavey about 13 years@Andew Hare why of course :) > "ADateTimeOffset is the new preferred type to use for the most common date time scenarios." - blogs.msdn.com/b/bclteam/archive/2007/06/14/…
-
Andrew Hare about 13 years@MattDavey - Very cool :) I don't think that all uses of DateTime should be switched over to DateTimeOffset though, just for some cases. Check out the "Usage Guidance" at the bottom of the article.
-
MattDavey about 13 yearsyeah my claims as to the deprecation of DateTime were slightly over zealous, there is still a place for it :) I think the reason DateTimeOffset hasn't been widely adopted yet is its slightly confusing name.. people tend to assume it represents an offset to a DateTime (a lot like TimeSpan), whereas it actually represents [date + time + offset].
-
SteveCinq almost 6 yearsI think it's weird that there is no
date
ordateTime
alias forSystem.DateTime
in C#.