在MySQL中存储负数日期之前要考虑什么?

时间:2021-09-17 16:49:30

I'm working on a project now that will require me to enable users to store negative-dates in the database. These dates have the potential to span many thousands of years BC, and as late as 'Today.' I've worked on many projects that stored dates, but they were all relatively-recent dates, and none of them were ever negative (BC).

我正在开发一个项目,这将要求我允许用户在数据库中存储负数日期。这些日期有可能跨越公元前几千年,并且可能延迟到“今天”。我曾参与许多存储日期的项目,但它们都是相对较新的日期,并且没有一个是负面的(BC)。

What types of things should I take into considering when working with this type of data? I'm fully aware of the many calendar-shifts that have taken place in history, but I will be working with the modern calendar and not worrying too much about doing conversions. However, any information about conversions would be greatly appreciated as it is a very relevant topic, and one that I am academically interested in although not required to focus on during this project.

在处理此类数据时,我应该考虑哪些类型的事情?我完全了解历史上发生的许多日历变化,但我将使用现代日历,而不是过多地担心转换。但是,任何有关转换的信息都会受到高度赞赏,因为它是一个非常相关的主题,而且我在学术上感兴趣但不需要在此项目期间关注。

Update: I'll be story YYYY-MM-DD (That format isn't required)

更新:我将成为故事YYYY-MM-DD(不需要该格式)

2 个解决方案

#1


How precise does your storage need to be? Is it years, days, or hours/minutes. If you are only looking at Days or Years, then maybe you don't need to actually store the Date, but rather an Offset of +/- Day/Years from your 0 Date

您的存储需要多精确?是年,日,或小时/分钟。如果您只查看天或年,那么您可能不需要实际存储日期,而是从0日期开始+/-日/年的偏移量

#2


I had the similar problem and I wanted to continue relay on date fields in the DB to allow me use date range search with accuracy of up-to a day for historic values. (My DB includes date of birth and dates of roman emperors...)

我有类似的问题,我想继续在数据库中的日期字段中继,以允许我使用日期范围搜索,精确度为历史值的一天。 (我的DB包括出生日期和罗马皇帝的日期......)

The solution was to add a constant year (example: 3000) to all the dates before adding them to the DB and subtracting the same number before displaying the query results to the users.

解决方案是在将所有日期添加到数据库之前向所有日期添加一个常量年份(例如:3000),并在向用户显示查询结果之前减去相同的数字。

If you DB has already some dates value in it, remember to update the exiting value with the new const number.

如果DB中已经有一些日期值,请记住使用新的const数更新exiting值。

#1


How precise does your storage need to be? Is it years, days, or hours/minutes. If you are only looking at Days or Years, then maybe you don't need to actually store the Date, but rather an Offset of +/- Day/Years from your 0 Date

您的存储需要多精确?是年,日,或小时/分钟。如果您只查看天或年,那么您可能不需要实际存储日期,而是从0日期开始+/-日/年的偏移量

#2


I had the similar problem and I wanted to continue relay on date fields in the DB to allow me use date range search with accuracy of up-to a day for historic values. (My DB includes date of birth and dates of roman emperors...)

我有类似的问题,我想继续在数据库中的日期字段中继,以允许我使用日期范围搜索,精确度为历史值的一天。 (我的DB包括出生日期和罗马皇帝的日期......)

The solution was to add a constant year (example: 3000) to all the dates before adding them to the DB and subtracting the same number before displaying the query results to the users.

解决方案是在将所有日期添加到数据库之前向所有日期添加一个常量年份(例如:3000),并在向用户显示查询结果之前减去相同的数字。

If you DB has already some dates value in it, remember to update the exiting value with the new const number.

如果DB中已经有一些日期值,请记住使用新的const数更新exiting值。