Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4579212
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:36:36+00:00 2026-05-21T20:36:36+00:00

We’re creating a historic archive for a world history database and we need a

  • 0

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:

  1. 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.

  2. 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;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T20:36:37+00:00Added an answer on May 21, 2026 at 8:36 pm

    Use something like this SQL (using my own table structure, not the one you had though):

    DROP TABLE IF EXISTS time_dimension;
    CREATE TABLE time_dimension (
            id                      INTEGER PRIMARY KEY,  -- year*10000+month*100+day
            db_date                 DATE NOT NULL,
            year                    INTEGER NOT NULL,
            month                   INTEGER NOT NULL, -- 1 to 12
            day                     INTEGER NOT NULL, -- 1 to 31
            quarter                 INTEGER NOT NULL, -- 1 to 4
            week                    INTEGER NOT NULL, -- 1 to 52/53
            day_name                VARCHAR(9) NOT NULL, -- 'Monday', 'Tuesday'...
            month_name              VARCHAR(9) NOT NULL, -- 'January', 'February'...
            holiday_flag            CHAR(1) DEFAULT 'f' CHECK (holiday_flag in ('t', 'f')),
            weekend_flag            CHAR(1) DEFAULT 'f' CHECK (weekday_flag in ('t', 'f')),
            event                   VARCHAR(50),
            UNIQUE td_ymd_idx (year,month,day),
            UNIQUE td_dbdate_idx (db_date)
    
    ) Engine=MyISAM;
    
    DROP PROCEDURE IF EXISTS fill_date_dimension;
    DELIMITER //
    CREATE PROCEDURE fill_date_dimension(IN startdate DATE,IN stopdate DATE)
    BEGIN
        DECLARE currentdate DATE;
        SET currentdate = startdate;
        WHILE currentdate < stopdate DO
            INSERT INTO time_dimension VALUES (
                            YEAR(currentdate)*10000+MONTH(currentdate)*100 + DAY(currentdate),
                            currentdate,
                            YEAR(currentdate),
                            MONTH(currentdate),
                            DAY(currentdate),
                            QUARTER(currentdate),
                            WEEKOFYEAR(currentdate),
                            DATE_FORMAT(currentdate,'%W'),
                            DATE_FORMAT(currentdate,'%M'),
                            'f',
                            CASE DAYOFWEEK(currentdate) WHEN 1 THEN 't' WHEN 7 then 't' ELSE 'f' END,
                            NULL);
            SET currentdate = ADDDATE(currentdate,INTERVAL 1 DAY);
        END WHILE;
    END
    //
    DELIMITER ;
    
    TRUNCATE TABLE time_dimension;
    
    CALL fill_date_dimension('1-01-01','2015-01-01');
    OPTIMIZE TABLE time_dimension;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
In my XML file chapters tag has more chapter tag.i need to display chapters
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I need a function that will clean a strings' special characters. I do NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.