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:

Share:
12,244
gh9
Author by

gh9

Software developer, database analyst

Updated on July 07, 2022

Comments

  • gh9
    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
    MattDavey about 13 years
    As of .NET 4, DateTimeOffset is the recommended way to represent date/time information. DateTime is essentially deprecated.
  • Andrew Hare
    Andrew Hare about 13 years
    @MattDavey: [citation needed] :)
  • MattDavey
    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
    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
    MattDavey about 13 years
    yeah 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
    SteveCinq almost 6 years
    I think it's weird that there is no date or dateTime alias for System.DateTime in C#.