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 3632838
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:34:34+00:00 2026-05-19T00:34:34+00:00

I have a MySQL DB and I need to be able to store dates

  • 0

I have a MySQL DB and I need to be able to store dates earlier then 1970 so I need a custom way to store dates. In my case, I need to be able to store dates up to the present and as far back as history goes. Obviously earlier events in history require less accuracy – days, months, even years become less important, as we do not have this historical information. The main query involving dates will be to select records between two given dates.

I have thought to use this format:

Year - int(6) | Month - tinyint(2) | day - tinyint (2) | time - time | AD tinyint (1) | mya - int (11)
But when it comes to actually using data in this format it becomes difficult. For example, if I want to get all records between two dates it would be like (pseudocode not SQL):

get all where
year between minYear and maxYear
if year == minYear, month >= minMonth
if year == maxYear, month <= maxMonth
if month == minMonth, day >= minDay
if month == maxMonth, day <= maxDay
if day == minDay, time >= minTime
if day == maxDay, time <= maxTime

or something, which seems like a right pain. I could store seconds before/after 0 AD, but that would take up way too much data! 2011 = 6.4 billion seconds since 0 AD. Does anybody have any ideas for this problem?

  • 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-19T00:34:35+00:00Added an answer on May 19, 2026 at 12:34 am

    You need at least one date to create an interval. I use one date field for start_date and an interval which can be a number of seconds or a fixed interval like ENUM(day,month,year). This depends on the data that you are working with.

    For DATE the supported range is ‘1000-01-01 00:00:00’ to ‘9999-12-31 23:59:59’, but this means that although earlier values might work, there is no guarantee. I see you can use 0001-01-01 with no problems.

    FOR BC values.
    I dont know if there is a standard but I’ve seen systems that state their own starting point. Lets say your data will be pre AD but not longer that 1000 BC. You can state your 0 year as -2000, you apply (year- 2000) difference for all dates and maybe even build a wrapper Date class which applies only to your project. You can assign the time as an integer an do all operations with it with no problem, especially if you dont work with days or months granularities. Current calendars are not reliable to work in the past as the accuracy of date was wrongfully calculated for centuries, and repaired by some hotfixes that can do calculations pretty difficult.

    // lets save the 1st of January 214 BC
    214-2000 = -1786
    save the data as 01-01-1786
    // you will probably want to save it actually as 01-01-1785 
    // to compensate for the loss of the year 0
    

    I would recommend you to keep the date format as it will allow you to do fast DATE operation directly in mySql.

    Update for calculating the leap years in your class:

    if year modulo 400 is 0
       then is_leap_year
    else if year modulo 100 is 0
       then not_leap_year
    else if year modulo 4 is 0
       then is_leap_year
    else
       not_leap_year
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.