We’re creating a historic archive for a world history database and we need a date lookup table which references all dates in AD. How to go about creating the values for this table – from 1AD to 2011 as YYYY/MM/DD? Database is MySQL.
Problems:
-
I’m using Excel to pre-populate the dates, then import into MySQL as: YYYY/MM/DD but Excel doesn’t recognize years like 0007, 0008, etc so I can’t auto-copy cells to generate dates. I have to manually do it and this will take days to go from 1AD to year 2011 as YYYY/MM/DD.
-
Leap years were introduced on 1752. If I programmatically generates dates how do I handle cases prior to 1752 with no leap years? It will generate wrong dates.
My table:
CREATE TABLE `dates` (
`date_id` int(10) NOT NULL,
`format` char(10) NOT NULL,
`century` int(10) NOT NULL,
`decade` int(10) NOT NULL,
`year` int(10) NOT NULL,
`month` int(10) NOT NULL,
`week` int(10) NOT NULL,
`day` int(10) NOT NULL,
`month_year` int(10) NOT NULL,
`week_year` int(10) NOT NULL,
`week_month` int(10) NOT NULL,
`day_year` int(10) NOT NULL,
`day_month` int(10) NOT NULL,
`day_week` int(10) NOT NULL,
PRIMARY KEY (`date_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Use something like this SQL (using my own table structure, not the one you had though):