How to store approximate dates in MySQL?

I need to keep dates like Summer 1878 or Early June 1923, or even Midday on Tuesday in August. How do you suggest me to do this?

I considered breaking the date and time into separate (integer) columns and providing each column with an auxiliary (integer) column containing a range (0, if accurate; NULL, if unknown). But I'm sure there are other ways ...

Thanks!

+4
source share
8 answers

In the end, I decided: a column for each of the date components (year, month, day, hour, minute, second) and accompanying columns for the range of each of them (year_range, month_range, day_range, hour_range, minute_range, second_range), mainly because that this method allows me to indicate that I know for sure that a particular photo was taken in August (for example) in the late 60s (year = 1868, year_range = 2, month = 8, month_range = 0).

Thank you all for your help!

0
source

I use Postgres and I wanted to do the same. Perhaps you can do this the same way I do if MySQL has similar geometric types: http://www.electricwords.org/2008/11/fuzzy-date-matching-in-postgresql/

+3
source

Almost no matter what you do, you will almost certainly not be able to get a database to do the hard work for you. Thus, you are left with two options: 1 - Use the natural strings as you described 2 - Keep accurate data, as well as the accuracy of this date.

For example, you can store “5:10:23 pm September 23, 1975,” “plus or minus 6 months,” and when someone wants to look for entries that occurred in this timeframe, it may appear.

This does not help with queries, because as far as I know, MySQL does not provide any support for tolerances (and others that I know of). You should basically query everything and then filter yourself.

+3
source

Since “Midday on Tuesday in August” (“Sunday on La Grande Jatte Island?”) Does not indicate a year, the only real solution is your table of all date and time components, all with a zero value.

In other words, you are merging your data.

You have two (admittedly) things: a human readable string, ad_date, and a number of possible dates.

If you can specify at least a range, you can do this:

create table artwork { artwork_id int not null primary key, name varchar(80), ... other columns date_description varchar(80), earliest_possible_creation_date datetime latest_possible_creation_date datetime } insert into artwork( name, date_description, earliest_possible_creation_date, latest_possible_creation_date ) values ( 'A Sunday Afternoon on the Island of La Grande Jatte', 'Mid-afternoon on a Tuesday in August' '1884-01-01', '1886-12-31' ), ( 'Blonde Woman with Bare Breasts', 'Summer 1878' '1878-05-01', '1878-08-31' ), ( 'Paulo on a Donkey', 'Early June 1923', '1923-06-01' '1923-06-15' ); 

This allows you to display everything you want and search for:

 select * from artwork where @some_date between earliest_possible_creation_date and latest_possible_creation_date; 

And, obviously, the “date of creation” (the date the artist created the work) is completely different from the “date depicted in the work,” if the latter can be determined at all.

+2
source

I do not think that any native MySQL date representation will work for you. Your two-column solution will work well if paired with a Unix timestamp (generated using the UNIX_TIMESTAMP() function with a MySQL date as an argument). Use the second column (range width) for the upper and lower bounds of your selections and make sure that the date column is indexed.

+1
source

create a table with a list of values ​​that you might want, such as Early or Summer. then no matter what you have, the settings may have an algorithm that sets the foreign key depending on the date.

0
source

In response to Chris Arguin's answer, there is another datetime column in the second column that you can use to store +/-, then you will have to write a query that uses both columns to get an approximate datetime.

0
source

Use two dates and determine the start and end dates of the fuzzy area. For things like Summer 1878, enter 18780621 to 18780920. At the beginning of June 1923 you have to decide when it ends early, maybe from 19230601 to 19230610. This allows you to choose against values. After that, you may want to filter out, but that will help you close.

For those who do not have years, you will have to find another system.

0
source

All Articles