HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMinor

Best way to handle dates prior to 1000 A.D. in MySQL?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
handledateswaymysql1000priorbest

Problem

I am creating a database for records that extend prior to 1000 AD, but MySQL Date and DateTime fields only support dates starting at 1000.

Is there a way that would be more convenient than either using a bigint type to count seconds before/after 1/1/1970 using a Unix timestamp, or switching to a database software that supports larger date ranges?

Solution

No native RDBMS date data type is going to do for applications that require very old (and for some, even distant future) dates.

If I were you, I'd use a string type for the native storage and stick with a place-significant format like: +YYYY-MM-DD to accomodate BC/AD and any foreseeable historical or reasonable future date.

If it might help, you could build a library class that converts your internal storage format into a more presentable one for the UI layer. You might even include library functions that convert to a native date type, if your language of choice supports the dates that you will have in your database.

Context

StackExchange Database Administrators Q#7077, answer score: 9

Revisions (0)

No revisions yet.