SqlDateTime.MinValue != DateTime.MinValue, why?

后端 未结 5 2046
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-27 13:59

I wonder, why SqlDateTime.MinValue is not the same as DateTime.MinValue?

5条回答
  •  遥遥无期
    2020-11-27 14:27

    1753 was the date of the first adopter of the Gregorian calendar (England). As to why this was chosen over 01/01/0001 - it is no doubt legacy from when SQL Server was Sybase back in the 1990s. They must've made the design decision early on and the Microsoft SQL team haven't seen a reason to change it.

    Since the explosion of .NET and the integration of it into Sql Server, there is now the DateTime2 object for compatability. If you're an NHibernate user, you can provide this type in your type mappings to avoid DateTime.Min problems

    .NET Dates cater for other calendars besides the Gregorian one:

    • Calendar
      • ChineseLunisolarCalendar
      • EastAsianLunisolarCalendar
      • GregorianCalendar
      • HebrewCalendar
      • HijriCalendar
      • JapaneseCalendar
      • JapaneseLunisolarCalendar
      • JulianCalendar
      • KoreanCalendar
      • KoreanLunisolarCalendar
      • PersianCalendar
      • TaiwanCalendar
      • TaiwanLunisolarCalendar
      • ThaiBuddhistCalendar
      • UmAlQuraCalendar

    The JulianCalendar infact pre-dates DateTime.MinValue

提交回复
热议问题