P
P
Paka2017-03-16 12:38:16
MySQL
Paka, 2017-03-16 12:38:16

How to store a time interval in a database (mysql)?

I need to store the number of days-hours-minutes-seconds in the field to add this number to the saved date. How can I do that?
Example.
Field A stores 2000-01-01 00:00:00
Field B stores ????-??-01 00:05:00 = 1 day and 5 minutes, how can this be stored?
Or is it possible to store the interval only in seconds as an integer?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
Optimus, 2017-03-16
@Paka

Consider the TIMESTAMP field type and yes you can seconds and just add to it

A
Alexander Pushkarev, 2017-03-16
@AXP-dev

Redis

A
Anton Anton, 2017-03-16
@Fragster

For a similar task at the time, I made two columns - INT = day number and TIME - time.
The advantage is that they can be shown directly to the user, and also saved without conversion.
In general, you can store at least the number of seconds, but then there will be a jamb with the translation of the clock (now it is no longer relevant, but suddenly).
And the date to which to add is already a full-fledged date-time with a time zone.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question