Reputation: 31
I'm working on a journaling system in C# at our local church, but I've run into trouble with the database connection when storing birth dates. According to MSDN the earlist date possible to represent is January 1st year 1. How am I supposed to record the birth date of Jesus Christ and earlier personalities that are important us?
Upvotes: 3
Views: 221
Reputation: 21
http://msdn.microsoft.com/en-us/library/system.globalization.gregoriancalendar.getera(v=VS.100).aspx
Upvotes: 1
Reputation: 21
If you are free to decide on type of calendar then I would recommend you to go-ahead with the Gregorian calendar, which has the
ability to recognize two eras: B.C. and A.D.
http://msdn.microsoft.com/en-us/library/system.globalization.gregoriancalendar.aspx
Upvotes: 1
Reputation:
Simple answer - store the day, month and year as separate numeric fields. The day and month can be combined into a day-of-the-year value, but you need to watch out for leap years.
Alternative answer - there are standard ways to convert a date into a day-number and back...
http://en.wikipedia.org/wiki/Julian_day
If you do the conversion yourself, you're basically storing a number (that just happens to represent a date) so you should have no problems. Well - other than making sure your conversions are correct.
Upvotes: 0
Reputation: 8232
You are going to have to roll your own class to handle BC dates in .NET, and store them in the database either as strings or as separate fields for year, month day (depending on what accuracy is required) if you require searching and sorting to be performed on the database side (which I assume you would).
SQL Server's support for dates is more restrictive than .NET's (it only goes back as far as 1753 or 1752 or thereabouts).
This blog post is one possible implementation, albeit a pretty limited one as it only stores the year. But I am sure you could modify it as necessary for your needs. For instance, it could probably do well to implement some interfaces such as IComparable, IEquatable, IFormattable and possibly IConvertible as well if you're keen so it can better interact with the rest of the framework.
Upvotes: 1