R
R
REDkiy2015-12-09 15:24:18
Python
REDkiy, 2015-12-09 15:24:18

How to store dates in a database?

I am developing a web application. I use Python3, flask and sqlalchemy.
It is necessary to store a large number of dates in the database. They will be compared, hit in the range of dates will be checked. A selection of date ranges will be made, for splitting into intervals. Samples will also be made depending on the year, month, day, hour and minute, in various variations. For example, only by one year or by date and hour.
Now I'm leaning towards the following solution:
Get date from form to datetime -> convert datetime to timestamp (UNIX form) -> save to database.
For sampling, I convert the text date to datetime -> datetime to timestamp -> I look at matches in the database.
The question is that I don’t quite understand how, for example, using timestamp to make a selection for a certain month, but with different years and so on.
As generally it is better to store dates in similar conditions. The application is very much focused on working with dates, as a result, a separate table was allocated for them.
In general, the work will be somewhat reminiscent of a calendar, however, the splitting of dates will be from a year to 1 minute and the search for all kinds of intersections, hits in the range, and so on.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Kitaev, 2015-12-09
@deliro

Store in a database-native format. For example, timestamp with time zone in Postgres. Don't forget indexes.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question