2

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.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Djenny Floro
  • 57
  • 11
  • 1
    possible duplicate of [What is the best way to handle bc dates in .net / sql server?](http://stackoverflow.com/questions/5058709/what-is-the-best-way-to-handle-bc-dates-in-net-sql-server) – GarethD Mar 07 '14 at 11:05
  • I'll modify my question since this partially answer me. Thanks for pointing it out to me, I missed it in my search. – Djenny Floro Mar 07 '14 at 11:14
  • @GarethD with these changes, do you see better why it's not a duplicate, or do you thinks I missed a point in the post that should answer me ? – Djenny Floro Mar 07 '14 at 11:30

1 Answers1

2

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

Ricardo Appleton
  • 679
  • 10
  • 22
  • This solution is quite good actually, it's what I needed. But could you please hint me at how to screen the year for example? I'm struggling with how to break down the ISO format into a "year" "day" and "month"... sorry. – Djenny Floro Mar 07 '14 at 12:37
  • @Ricado Appleton Do you think that this : http://pastebin.com/jj6PKCnZ is properly using your answer ? I'm not sure that passing from string to int and then int to string is quite good.. – Djenny Floro Mar 07 '14 at 13:09
  • Got that part working like a charm thanks for the help – Djenny Floro Mar 07 '14 at 15:21
  • mind that if your date's year is less than 1000 that class won't work properly. Eg. date 07001012 as an int is stored as 7001012, and if you get the first four chars you'll get 7001, not 0700. You should first assert the signal of your string and pad left with 0's up to 8 in length. Something like `time.ToString().PadLeft(8, '0').Substring(0, 4);` – Ricardo Appleton Mar 10 '14 at 12:36