Question

I'm doing a c# program with a SQL Server database, and I'm having trouble to chose from all the solutions proposed to handle negative and positive dates. Actually, here are the solutions I've found around :

  • Use a Boolean to indicate BC or AC;
  • store date components (jj, mm, (-)aaaa) as int and make a class that handles verification to see if the date exist or not.

I'm sure there are other type of ways shown out there, but those are actually the most understandable ways for me.

The software is for helping with character books's birthdays and other character activities in books. So say the starting date of the book is "10/01/0023" (jj/mm/aaaa) which is the beginning of the era the characters are in, and a character is already 80 years old at that time, he's born "02/03/-0057".

My question centers around which of the two solutions above would work best in this context. I've read the thing linked to me, but I don't quite see how for example, the software can handle sorting the characters from older to younger, and verify that the date of birth is not posterior to the date of death, which would make no sense...

I hope this clarify my question ?

I sincerely thanks anyone who'll take the time to read this.

Était-ce utile?

La solution

I'd then suggest you'd store your dates as a number in ISO format: YYYYMMDD

This way you'd be able to store dates BC as -YYYYMMDD and AD as YYYYMMDD. It also makes it easy to compare between dates:

eg. if ( -00801012 < 00110214 ) { ... } or if ( 19741015 < 20140228 ) { ... }

You'd need to assert the signal when you want to show the date on the screen. boolean isAD = false; If ( mydate > 0 ) { isAD = true; }

and you'd use abs to format your date

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top